Skip to content

Instantly share code, notes, and snippets.

@dsummersl
Created November 30, 2012 12:19
Show Gist options
  • Save dsummersl/4175461 to your computer and use it in GitHub Desktop.
Save dsummersl/4175461 to your computer and use it in GitHub Desktop.
Applescript script for toggling applications in and out of fullscreen mode.
on run argv
(*
Toggle an application from full screen to non full screen (or the reverse).
Parameters:
1: application name(ie, Chrome)
2: boolean (true/false).
When true ensure that the application is in full screen mode (if not, make it so)
When false ensure that the application is NOT in full screen mode (if not, make it so)
*)
set theapp to item 1 of argv
if item 2 of argv is "false"
set toggleOnFull to true
else
set toggleOnFull to false
end if
tell application theapp
activate
delay 2
(*
Initially from http://stackoverflow.com/questions/8215501/applescript-use-lion-fullscreen
*)
set isfullscreen to false
tell application "System Events" to tell process theapp
set isfullscreen to value of attribute "AXFullScreen" of window 1
end tell
--display dialog "var " & isfullscreen
if isfullscreen is toggleOnFull then
tell application "System Events" to keystroke "f" using { command down, control down }
delay 2
end if
end tell
end run
@loshlee
Copy link

loshlee commented Jun 13, 2013

Requires enabling "Enable access for assistive devices". In Mountain Lion that can be found in the Accessibility System Preference item.

@stevenjohn
Copy link

Hi there, I am using this in Mavericks - and use QuickSilver trigger to run the script from keyboard shortcut.

It works fine when I run it from the AppleScript Editor, but from the keyboard trigger i randomly (it seems) get this error:

26/04/2014 9:58:37.126 am Quicksilver[15188]: Run Script: System Events got an error: Can’t get window 1 of process "Terminal". Invalid index.

My script I have used, changing your slightly is:

on run argv

set toggleOnFull to false

set myList to {"Google Chrome", "Safari", "Firefox", "Mail", "Skype", "Terminal", "Sublime Text", "Calendar"}
repeat with theItem in myList

    tell application theItem
        activate
        delay 3
        (* 
  Initially from http://stackoverflow.com/questions/8215501/applescript-use-lion-fullscreen
*)
        set isfullscreen to false
        tell application "System Events" to tell process theItem
            set isfullscreen to value of attribute "AXFullScreen" of window 1
        end tell
        --display dialog "var " & isfullscreen

        if isfullscreen is toggleOnFull then
            tell application "System Events" to keystroke "f" using {command down, control down}
            delay 4
        end if
    end tell

end repeat

end run

Any ideas on why this message appears?

Kind regards, Steve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment