0

I am trying the fullscreen just one of several Preview tabs with AppleScript by fn + F how can I select the tab by its name?

tell application "Preview" to activate
delay 0.1
tell application "System Events" to tell process "Preview"
    key down 63
    keystroke "f"
    key up 63
end tell

1 Answer 1

0

Here's an OOP approach:

set foundTab to findTabWithName("IMG_5116.jpg")
if foundTab is not missing value then
    foundTab's fullScreen()
end if
    
to findTabWithName(documentName)
    try
        tell application "Preview"
            set appWindow to first window whose name is documentName
        end tell
    on error
        return missing value
    end try
    _newInstance(appWindow)
end findTabWithName


on _newInstance(pAppWindow)
    script PreviewTabInstance
        property appWindow : pAppWindow
        
        to focus()
            try
                tell application "System Events" to tell process "Preview"
                    click (first menu item of first menu of menu bar item "Window" of first menu bar whose title is equal to name of my appWindow)
                end tell
                true
            on error
                false
            end try
        end focus

        to closeTab()
            tell appWindow to close
        end closeTab
            
        to fullScreen()
            focus()
            activate application "Preview"
            tell application "System Events" to tell process "Preview"
                try
                    click menu item "Enter Full Screen" of menu 1 of menu bar item "View" of menu bar 1
                end try
            end tell
        end fullScreen
    end script
end _newInstance
1
  • I saw your other question about closing a tab, so I added that routine here as well. Mar 30, 2022 at 2:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .