When closing a specified app or minimizing it give focus to another a specific app

I use Studio One to create and mix music. If that program is running I would like to automatically return to it and have it in focus as soon as I close or minimize another app.

Use case: When using Studio One I may look up info in a browser or look for files in finder etc. When I close or minimize those apps/windows I want to be able to go back to controlling Studio One with hotkeys without clicking on it's window to give it focus.

Can this be done? If possible with the apps that (upon closing) qualify as a trigger limited to a few specified ones.

Thanks for any pointers.

This is easily doable with the Activate a Specific Application action.

Example Screenshot (click to expand/collapse)

To trigger a macro when an application deactivates, use the Application trigger, and set it to when any application deactivates if you want it to return to Studio One when any app deactivates (I don’t recommend this), or set it to when specific applications deactivate. If you want it to fully execute only when Studio One is running, your first action should be some sort of verification that the app is running, that cancels the macro if it isn’t. See the Redirect Control Flow (specifically, the Cancel Just This Macro portion) and Assert actions for more info.

Example Screenshot (click to expand/collapse)

Thank you @cdthomer That all makes sense. I'll give it a try and report back.

1 Like

@cdthomer I works partly but not quite with the desired result yet.

The trigger works for closing another app but not for minimizing it. Some apps need to be running in the background because they deal with the routing of signals for example. So these apps I don't close but minimize and was hoping to have that function as a trigger as well. I can see that might be difficult.

Studio One is being activated (it's menu appears at the top), but the main window still needs a click in order to receive hot key commands. This might be a Studio One particularity. Maybe this can only be achieved by making a mouse click part of the macro. That shouldn't be too hard but isn't the most elegant solution.

If you have any suggestions I would love to hear them. Thanks for your help.

You may not close them, but can you hide them and have them still work properly? I have found a lot of folks use different terms interchangeably... such as “maximize” and “zoom”... which are two different things in macOS, as well as “close” when they really mean “hide”... since those are also two different things. So if the app(s) in question can still run properly while being hidden, then that opens up more options.

Sounds like it’s being activated, but not brought to the front. Did you check the two boxes in the activate a specific application action like I showed in the screenshot? If not, try that. If you did, then try adding a Manipulate a Window action, and select “Bring to front” as the option.

The activation works now. Excellent! The only missing link is the macro being triggered when a specified app is minimized. When I say minimize I mean pressing the yellow/orange button in the top left of the app's window. Is that a state change that can be detected?

For that, you can use the Focused Window trigger. Note that when you minimize a window, the app is not minimized, only that window.

You are right. Minimizing a window with the yellow dot keeps the app active, so my remark about minimizing the app wasn't worded correctly. I minimize it's active window and want that to be a trigger.

I'm not quite clear however about your suggestion to use Focussed Window Trigger for this. Using the debugger I notice no trigger activity for each of the different options this trigger has when I minimize a window. As soon as I close a window the trigger fires, but not when I minimize it.

Maybe I didn't understand you correctly?

Thanks again for your help.

Since I have limited experience with this trigger, I looked at it more closely and it appears that minimizing a window does not work to trigger it. See the example test macro below. So to sum it up, I’m not sure if you would be able to detect a window minimizing and trigger a macro that way.

Download Macro(s): Detect window changes.kmmacros (2.7 KB)


  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System Information
  • macOS 13.5.1
  • Keyboard Maestro v10.2

Ah, OK. So that was my impression too.

Well, at least we tried :slight_smile:

I'll mark that reply as a solution because knowing that it can't be done is an answer too. Thanks for your time and input.

What about:

Control + any mouse click
(Or F1-F2 etc)


  1. hide app currently at front
    2 activate a specific app

Command H ( hide finder window )
Will trigger

  1. Command H
  2. Activate specific app when it's running
    If not running
    Trigger command H

Just using shortcuts instead of mouse clicks will increase your options.

Thank you for your suggestion.

Yes, that opens the door to more possibilities. The only drawback is that I wanted to create this macro to deal with my own built in habit of closing/minimizing an app and expecting the previous app that is then back at the front to be automatically active. This habit may stem from having been a Windows user for over 30 years (can't check if it actually works that way on PC). Basically I was hoping for a solution I didn't have to think about.

Your approach is obviously still better than no macro at all. Thanks.