Open an app in fullscreen via Terminal

I wonder if it's possible to open a program in Lion fullscreen mode via the Terminal. I want to write a short script which starts a bunch of programs in fullscreen mode, so that I only have to click once to start my working environment.


Solution 1:

Here it is:

/usr/bin/osascript -e 'tell application "Safari"' -e "activate" -e 'tell application "System Events"' -e 'keystroke "f" using {control down, command down}' -e "end tell" -e "end tell"

Here it is in a clearer form (but you can't run it this way):

/usr/bin/osascript -e "tell application \"Safari\"" 
-e "activate"
-e "tell application \"System Events\""
-e "keystroke \"f\" using {control down, command down}"
-e "end tell"
-e "end tell"

And this is it as formatted AppleScript:

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

It works by first opening a Safari window if one is not currently open. Then it simulates the Control ⌃-Command ⌘-F keystroke which tells the Safari window to become full screen.

If you want to make the window the max-size it can be without becoming full screen (i.e. taking up all the space below the menu bar at the top):

tell application "Finder"
    set desktopSize to bounds of window of desktop
end tell

tell application "Safari"
    activate
    set bounds of window 1 to desktopSize
end tell

Which would become this in Terminal:

/usr/bin/osascript -e "tell application \"Finder\"" -e "set desktopSize to bounds of window of desktop" -e "end tell" -e "tell application \"Safari\"" -e "activate" -e "set bounds of window 1 to desktopSize" -e "end tell"

For Chrome, do this:

tell application "Google Chrome"
    activate
    make new window
    tell application "System Events"
        keystroke "f" using {control down, command down}
    end tell
end tell

So it would be this in Terminal:

/usr/bin/osascript -e "tell application \"Google Chrome\"" -e "activate" -e "make new window" -e "tell application \"System Events\"" -e "keystroke \"f\" using {control down, command down}" -e "end tell" -e "end tell"

Hope this helps!

Solution 2:

This won't work with applications that don't use native full screen windows, but should work with some that don't use the standard shortcut for entering full screen. A few applications have different process names and application names.

set a to "Notes"
set bid to id of application a
tell application a
    reopen -- open a new default window if there are no windows
    activate -- make frontmost
end tell
tell application "System Events" to tell (process 1 where bundle identifier is bid)
    click (button 1 of window 1 where subrole is "AXFullScreenButton")
end tell

Solution 3:

you can use browse to open arbitrary apps in full-screen mode.. It installs six convenience commands, four of which open the most common browsers in full-screen:

Launch Chrome Canary in Presentation Mode:

$ ca

Launch Chrome in Presentation Mode:

$ ch

Launch Firefox in full-screen Mode:

$ ff

Launch Safari in full-screen Mode:

$ sf

To launch anything in full-screen, run the command ccf (an applescript sending the CMD+CTRL+f keystroke) after a regular open to switch it to full-screen mode:

$ open -a Calendar; ccf

Should an app have an additional full-screen mode shortcutted by CMD+Shift+f (as Chrome does), use:

$ open -a "Google Chrome"; csf

Tip. If an app is slow to load, give it chance to load fully by inserting a pause before running the keyboard shortcut:

$ open -a "Google Chrome"; sleep 3; csf

Solution 4:

Here's instructions for Google Chrome. (This will open an Incognito window to full-screen.)

Go to /Applications/Google Chrome.app/Content/MacOS/. Rename the Google Chrome binary to something else (like chrome-bin) and create an executable bash script in its place (name the script Google Chrome just like the original executable file).

#!/bin/bash
open chrome-bin --new --args -incognito

osascript -e "tell application \"Google Chrome\"" -e "tell application \"System Events\"" -e "keystroke \"f\" using {control down, command down}" -e "end tell" -e "end tell"

Now, every time you launch Google Chrome it will launch full screen in Incognito mode. I use Incognito mode, but if you don't want that, just delete the -incognito flag.

Solution 5:

Here's an addition to @pasawaya's excellent answer. If you want to execute your applescript from the command line, you don't need to enter every line separately with the -e option.

osascript -e 'multi-line-applescript here' will work also. Example:

osascript -e 'tell application "Safari"
activate
  tell application "System Events"
    keystroke "f" using {control down, command down}
  end tell
end tell'