Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applescript to open an application in full-screen mode?

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?

like image 878
Eric Ho Avatar asked Mar 28 '16 22:03

Eric Ho


People also ask

How do I make my Mac open maximized apps?

On your Mac, move the pointer to the green button in the top-left corner of the window, then choose Enter Full Screen from the menu that appears or click the button . In full screen, do any of the following: Show or hide the menu bar: Move the pointer to or away from the top of the screen.

What is the Mac command for full screen?

If you like to use keyboard shortcuts, you can press Command + Control + F. That same keyboard shortcut is used to go in and out of full-screen mode. And finally, you can do things the traditional way. Once again, hover with your pointer over the top portion of your screen until you see macOS' menu bar.

Does Apple still use AppleScript?

AppleScript is a scripting language created by Apple Inc. that facilitates automated control over scriptable Mac applications. First introduced in System 7, it is currently included in all versions of macOS as part of a package of system automation tools.


2 Answers

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
like image 144
George WS Avatar answered Sep 19 '22 20:09

George WS


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
like image 22
iammcgaber Avatar answered Sep 21 '22 20:09

iammcgaber