Applescript to open an application in full-screen mode?

Eric Ho picture Eric Ho · Mar 29, 2016 · Viewed 12.3k times · Source

I'm trying to program Alfred to open my Terminal, Sublime Text, and Chrome with a workflow.

I would like for my terminal to open normally as a window, but I've been trying to get Chrome and Sublime to open full screen.

I was able to get Chrome to open up in full screen mode with:

on alfred_script(q)
   tell application "Google Chrome"
        tell window 1 to enter presentation mode
   end tell
end alfred_script

However, this did not translate to work with my Sublime Text.

What am I missing here?

Answer

George WS picture George WS · Jun 15, 2017

Another way to do this assuming you have not changed the default keyboard shortcut for "Enter Full Screen" is simply to have System Events invoke that shortcut (⌃⌘F). As with the other approach I've seen to doing this (changing the value of AXFullScreen—see mklement0's answer here for a thorough discussion of this method), this requires making the relevant window active.

For instance, to toggle the full-screen state of the frontmost window in Safari, run:

tell application "Safari" to activate
tell application "System Events"
        keystroke "f" using {command down, control down}
end tell