Detect when an application goes fullscreen

applescriptfullscreenterminal

I would like to detect that event from an Applescript. I have found the lsappinfo command-line app, which has a listen command that seems to fill my need exactly, but going fullscreen does show up in the output. Here is what I tried. First I ran in Terminal

lsappinfo  listen +all forever

Then I clicked on a Safari window, and then clicked on the green button to make it fullscreen, then exited fullscreen and went back to terminal to see the output. I then did it again but without going fullscreen, just clicking on a Safari window, and then clicking back on the Terminal window. In both cases, the sequence of events is

  1. FrontApplicationPresentationModeChanged, received by Safari
  2. PresentationModeChangedBecauseFrontApplicationChanged, received by Safari
  3. BecameFrontmost, received by Safari
  4. LostFrontmost, received by Terminal
  5. MenuBarAcquired, received by Safari
  6. MenuBarLost, received by Terminal
  7. FrontApplicationPresentationModeChanged, received by Terminal
  8. PresentationModeChangedBecauseFrontApplicationChanged, received by Terminal
  9. BecameFrontmost, received by Terminal
  10. etc

The "fullscreen event" should have shown up between 6 and 7 in this list but it is conspicuously absent!

This is on MacOS 10.12.6. It feels like a bug to me. Does somebody know whether it works on other versions of MacOS? Is there any other way to achieve my goal?

Best Answer

I am not sure if this solves your issue or not but the easiest way to detect whether or not a window is full screen would be to compare it's window dimensions to the window dimensions of your "desktop window". See below:

tell application "Finder" to set screenSize to bounds of window of desktop

tell application "Safari" to set windowBounds to bounds of front window

if windowBounds is equal to screenSize then
    return "It's Full Screen"
else
    return "Not Full Screen"
end if