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


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)
        tell application "Preview"
            set appWindow to first window whose name is documentName
        end tell
    on error
        return missing value
    end try
end findTabWithName

on _newInstance(pAppWindow)
    script PreviewTabInstance
        property appWindow : pAppWindow
        to focus()
                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
            on error
            end try
        end focus

        to closeTab()
            tell appWindow to close
        end closeTab
        to fullScreen()
            activate application "Preview"
            tell application "System Events" to tell process "Preview"
                    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
  • 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 .