Trigger a Macro When an Application Becomes Full-Screen

There is a way to do what you're asking if I read everything correctly, and I'm surprised it wasn't mentioned already. You can use the trigger for when a window's frame changes or the focused window changes. Then in your macro, you check if the front window is full screen and perform your necessary actions.

Here's the macro from the image. It's currently disabled, so you'll need to enable it again.

Full Screen Window Check.kmmacros (2.7 KB)

6 Likes

That strikes me as a very good idea.

I would probably add a test to make sure the changed window frame was in fact full-screen though.

-ccs

Yes, very good solution — thanks!

2 Likes

For anyone interested, I had to do something a little more complicated based on @TorreyB's suggestion. My macro needs to swap out the menubar icons when the full-screen status changes — so it needs to identify those moments when we go from full-screen to not-full-screen, or vice versa. (@TorreyB's macro as written wouldn't work for cases where we go from full-screen to not-full-screen.)

So here's what I've got. Note that before you run it for the first time, you need to create a variable called kIsFullScreen and set it to 0 (at a moment when you're not in full-screen mode).

Change Status Menu Icons for Full Screen.kmmacros (6.0 KB)

2 Likes

In your nested if condition, you should be able to remove the check if the front window is not full screen. This condition would be already be true because you're in the ELSE of that logic.

image

In a pseudo-code style my example macro is written like:

IF window is full screen
   do full screen actions
ELSE
   do not full screen actions
END IF

It does -- that's what the "Else..." section of the "If... Then... Else..." action is for. Since you can only be "full screen" or "not full screen", when the "full screen" test fails you skip to the "otherwise" section of the action.

One word of caution -- while the macro probably does what you want, it may not do exactly what you think it does! There's no "What was I before?", so simply re-sizing a "normal" front window is treated the same as switching out of full screen mode. In cases where that difference matters you'd have to track window state, for example by setting a global variable Global_wasFullScreen to true or false as appropriate every time your macro runs. You then be able to restrict your actions to when front window is not full screen AND Global_wasFullScreen == true.

One word of caution -- while the macro probably does what you want, it may not do exactly what you think it does! There's no "What was I before?", so simply re-sizing a "normal" front window is treated the same as switching out of full screen mode. In cases where that difference matters you'd have to track window state, for example by setting a global variable Global_wasFullScreen to true or false as appropriate every time your macro runs. You then be able to restrict your actions to when front window is not full screen AND Global_wasFullScreen == true .

Right, that's exactly what I did in the macro I posted above.

In your nested if condition, you should be able to remove the check if the front window is not full screen. This condition would be already be true because you're in the ELSE of that logic.

That's not correct — this is an "all of the following are true" IF condition. We're checking for cases where the full-screen status is out of sync with the global variable — so, cases where the front window is full-screen AND the variable says it's not, or cases where the front window is NOT full-screen AND the variable says it is. So we need to check both data points in both IF actions.

Apologies. I was focused on:

...which looks to be a mis-statement of the problem. I should have looked more closely at your solution!

Even though this has been marked "Solved", I've discovered a case in which neither of the conditions used above, Menu Item Exists or Front Window is Full Screen, works. The app is full screen, but the View menu shows "Enter Full Screen" greyed out. So the app is not either in Full or Not Full mode, it's not in Full Screen Mode because the menu item says "Enter Full Screen" but it's already in Full Screen Mode because the menu item is greyed out.

So far (I've only tested a few) the onty app I've found that can get into this state is Keyboard Maestro. I'm running v11.0.1. on Catalina. If it's an OS problem, which is very well could be, given the level at which the error occurs, then maybe it's been fixed in a later version.

Here's how I duplicate it, consistently:

  1. Open the KBM Editor, not full screen.
  2. Open another app or a window, not KBM, that you can use to recognize as being in the same Desktop Workspace as KBM.
  3. Activate KBM.
  4. Click the green Full Screen button in the KBM window frame.
  5. Use Mission Control or any other Desktop Switching method to move to the non-full-screen desktop that has just been vacated by the KBM editor. E.g., activate the app window that you created in Step 2.
  6. While you are in the Desktop Workspace that has been vacated by KBM, click the KBM icon in the dock.
  7. Notice that you are switched to the Full Screen KBM window. If you have another KBM window, such as the Preferences winow, open in the Desktop, you might notice that it gets activated when you click the Dock icon. In this case, just click the Dock icon again, until you switch to the Full Screen KBM window.
  8. In the Full Screen KBM window, move your mouse to the top of the screen to show the app menus.
  9. Click the View menu.
  10. Notice that in the View menu, the last item is "Enter Full Screen" and it is greyed out.

With a KBM macro running with a Space Change triggere, that looks for either of the above conditions when triggered, it will not detect that the app is in Full Screen. Obviously it misses the menu item because the proper text is not there. But the other test, Front WIndow of Front Application is Full Screen, also fails.

UPDATE: I don't know what's different, but the problem went away when I restarted the KBM Editor. Now, when I click the Dock Icon in Step 6, the KBM menu appears at the top of the screen. That View menu has the greyed out "Enter Full Screen", which is appropriate in the current context. Another click of the Dock icon goes to the Full Screen KBM Editor, and now the View menu there is as it should be, with an active "Exit Full Screen" option. And both Conditions work.

Go Figure ...

I like this solution. I have KM Application Palette at the bottom of the screen. If an application goes full screen, I have a macro that moves the palette to another monitor.

If I am watching a YouTube video in Chrome and I clicked on the expand icon in YT video to make the video fullscreen, this solution works. But, it didn't run if I am doing the same in Safari. Making YouTube fullscreen in Safari does not seem to register "The front window of Front Application is full screen". Any idea what I can use instead?