I would like to ensure a application is running in fullscreen using a shell command (or script). I've seen some approaches that tell the application to execute a keyboard shortcut (cmd+ctrl+f) but that will toogle the fullscreen mode, not ensure.


Here's an AppleScript that can do it. Pass true or false to switch mode. The script uses the value of AXFullScreen to determine whether the app is currently in full screen and will only switch if necessary.

Toggle an application from full screen to non full screen (or the reverse).
  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)
on run argv
  set theapp to item 1 of argv
    if item 2 of argv is "false"
    set toggleOnFull to true
    set toggleOnFull to false
    end if

  tell application theapp
    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

Source: https://gist.githubusercontent.com/dsummersl/4175461/raw/36811eab78ca5e1a25fbd547a44b3d9c8d0d424d/makeFullScreen.applescript

  • Hi @george-garside, I've tried the script with no success. I'm on Maverick and I get this error: makeFullScreen.applescript:787:792: execution error: System Events got an error: osascript is not allowed assistive access. (-1719) when running from CL osascript ~/Desktop/makeFullScreen.applescript HipChat true. I've added Chrome to the accessibility apps in the OSX settings, but I get the same error. Any ideas? – a--m Jul 18 '14 at 8:07
  • @dome You need to give osascript assistive access: run sudo sqlite3 /Library/Application\ Support/com.apple.TCC/TCC.db "INSERT or REPLACE INTO access VALUES('kTCCServiceAccessibility','/usr/bin/osascript',1,1,1,NULL)" – grg Jul 18 '14 at 12:44
  • Done that, I can see it adds the osascript in the pref panel, but after all I still get the same error: osascript ~/Desktop/makeFullScreen.applescript HipChat true /Users/am/Desktop/makeFullScreen.applescript:787:792: execution error: System Events got an error: osascript is not allowed assistive access. (-1719) – a--m Jul 18 '14 at 13:33
  • If someone got this working I would mark it as correct, but for some reason it doesn't work for me. I must be missing something here :/ – a--m Jul 21 '14 at 12:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .