8

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?

Eric Ho
  • 81
  • 1
  • 1
  • 2

2 Answers2

9

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
George WS
  • 3,903
  • 5
  • 27
  • 39
4

As found here (i need an applescript to open safari in full screen an to hide the toolbar on mavericks). The make new document line prevents the can't get window 1 error by opening a new tab if one has not previously been opened.

tell application "Safari"

    make new document
    
    activate

    delay 3

    tell application "System Events" to tell process "Safari"

        set value of attribute "AXFullScreen" of window 1 to true

    end tell

end tell
iammcgaber
  • 61
  • 4
  • 1
    System Events got an error: Can’t get window 1 of process "Safari". Invalid index. – Dmitry Grinko Apr 07 '18 at 16:17
  • I receive the following: "Script Error: System Events got an error: Script Editor is not allowed assistive access." – Glenn Wark Jan 27 '19 at 16:11
  • It works after allowing the Script Editor to access Accessibility in System Preferences. – Glenn Wark Jan 27 '19 at 16:18
  • error "System Events got an error: Can’t get window 1 of process \"Safari\". Invalid index." number -1719 from window 1 of process "Safari" – deleted May 26 '21 at 12:08
  • This is an error you get if Safari does not have a window currently open. I have edited the answer to prevent this. – iammcgaber May 27 '21 at 13:25