How to Set a Macro_B That Monitors if Other App in Front When Macro_A Is Running?


I have a Macro-A that runs at a fixed point every day.

This Macro-A has a lot of found image related functions, and the whole Macro-A running time needs to last about 90 minutes, so when the Macro-A is running (this Macro-A only needs to use three apps during the period).

If another app accidentally jumps out and goes to the top of the window during this period Macro-A will stop, because it cannot recognize the set image and it stops running.

I wonder if I can set a macro-B to run asynchronously and hide the window when there is other app at the top of the window.


Macro A could enable/disable Macro B to it is only active when Macro A is running (unless Macro A fails and aborts for any reason).

Macro B could be triggered by an Application trigger or a Focused Window trigger and decide whether it needs to take action.

Wherever macroA performs a found image action make sure the correct app window is at the front by inserting an Activate application action just before the found image activity. That way, the correct app window will always be available to macroA. You don’t really need a second macro to “police” your windows for you.

1 Like

Yes, this works – but macro A is a super long macro that has many found image actions.

I would need to insert many activate app actions.

Is there is a way that just monitors the windows situation will make the macro A more light.

The problem with your idea is that Macro B has to somehow know which of the 3 apps need to be in front while Macro A is working; in other words Macro B has to track the progress of Macro A somehow and I can’t see an obvious way of achieving that.

Sorry, my suggestion is how I’d do it.

1 Like

Does macro B need to run when macro A is running? How is macro B triggered? Those tie into @peternlewis's suggestion -- you could disable B at the start of A and re-enable it at the end, or start B with "If A is running then Cancel this Macro", if B doesn't use the same apps as A you could put it in a Group that isn't enabled when A's apps are frontmost, etc.

Does B need access to the UI or can you get round that somehow? That'll depend on what the macro does -- you could manipulate text files directly rather than via an app, move files by action/script rather than in the Finder, and similar.

Or can you change A to be less image dependent? Such long-running, UI-reliant, macros are inherently fragile (as you've found) and perhaps a change in process -- even a change of apps to ones that are more directly scriptable -- is worth considering.

Hey Somyan,

It seems to me you have a couple of options that are both arranged around the primary macro activating the secondary macro.

Secondary macro could do one of a couple of things:

  1. Use an Application Trigger with the deactivate option to make the given app activate any time it loses its frontmost status.

  2. Run a loop watching the CurrentApplication Token for changes and reactivate the desired app if necessary.

The biggest problem I foresee is if a background application opens a foreground window, and that can be more difficult to monitor.

It seems to me that you want to turn off every process that could interfere with your macro while it's running.

  • Quit unnecessary apps.
  • Mute the Notification Center.
  • Etcetera.


1 Like