When "Last Application" is current application

I'm creating a macro to toggle audio mute in Zoom regardless of which app is active: hit the hotkey and the macro activates Zoom, an if-then selects whichever of Mute Audio / Unmute Audio is active, and then the macro ends with an Activate Last Application action.

This works fine unless I am actually in Zoom when I hit the hotkey. I was hoping that the Activate Zoom action would set Zoom as the "last application" in that circumstance -- "I'm in Zoom and about to switch to something, so Zoom is the Last Application, and now I switch to -- Zoom!" But this doesn't happen; the Activate Last Application action switches me to whatever app I was last in before Zoom.

Is there any way to make this work without an extra if-then that checks to see whether Zoom is the front app and handles that case separately, or setting a variable to whatever the front app is when I hit the hotkey and then using that variable to set the front application by name at the end? I mean, both options work and I've got the macro running as desired, they're just less tidy than Activate Last Application.

Do others similarly think that an Activate Application action ought to set the Last Application to whatever was frontmost then, even if the active application doesn't actually change? Or is that not as intuitive to others as it is to me?

Try modifying this for Zoom and the appropriate menu option...
I do not see why it should not work from anywhere.

image

I have no problem selecting the appropriate menu command, thanks. My point is about the way the Activate Last Application action knows which application to activate, and how that is determined (or not) by a previous Activate a Specific Application action.

I prefer the way it works now -- that is the most logical and intuitive to me.
The "Activate Application" action only changes the app if the one app requested is NOT frontmost. So, to me, Last Application is the one that was frontmost prior to the current app.

3 Likes

I agree with this. Like doing a quick press of Command-Tab to switch apps, I think users' expectation is that what would come to the front is the prior app that was frontmost.

Is there any way to make this work without an extra if-then that checks to see whether Zoom is the front app and handles that case separately...

Is there a particular concern about adding an additional If-Then action?

No particular concern; like I said, I've got the macro working. But it would be tidier (and more intuitive to me, although not to others who have responded) if the Activate Last Application action consistently and reliably undid a preceding Activate An Application action, no matter which application that Activate action had activated.

I can imagine many other contexts in which I'd want to write a macro that opened with Activate An Application, did stuff, and then ended with Activate Last Application to go back to the original app. Instead, every such macro will open with a Set Variable originalApp to Text %Application%1% action followed by an Activate Application action, and close with a Use Variable originalApp to Set the Front Application by Name action. No biggie.

Yes, the Last Application is the application that was previously the front application.

An Activate Application that is activating the current application does nothing, so the Last Application remains unchanged.

Basically, for this case you'll need to keep track of the current application yourself and reset it to that.

As noted, if you use the Select a Menu Item action to select the menu item, Keyboard Maestro will, if necessary, bring Zoom to the front, perform the menu and then pop back, and this is all handled for your automatically.

1 Like

Hm, I thought I would have to activate Zoom in order to check which of Mute Audio or Unmute Audio was enabled, but then I remembered the %ActionResult% token, which lets me toggle audio mute without having to explicitly activate Zoom: just try one menu command and if it fails, try the other. A third way to achieve my goal, nifty!

Really I was just curious whether I was the only one for whom the behavior of Activate An Application wasn't entirely intuitive. I do seem to be, that's not a problem, I understand it now. Thanks, Peter and everybody!

1 Like

Ahahahah -- and now I have discovered that the Type A Keystroke action can send the keystroke to a background app! And although the menu command in Zoom changes between Mute and Unmute, a single keystroke works within the app to toggle it. So I don't have to do any if-then or error checking at all; I just have to send that keystroke to Zoom from whatever app I'm in.

Man, Keyboard Maestro just gets better and better the more closely you look at it. It's fractally awesome.

3 Likes