Automatically Set a Given App to Be Frontmost After a Set Amount of Time

Hi there Keyboard wizards!

I have a quit strange problem with a strange solution. I run a show with several audio apps. After a bit of time that I don't have the apps running audio as the Frontmost app, the sound starts to distort. I have tried to find a way of creating a macro that:

If "app" isn't frontmost for more than let's say 3 minutes. It automatically triggers a macro to set the app to frontmost. There is one more important thing that if another app that plays sound is frontmost, don't set "app" to front most (an exception).

Is this possible with KM?

All the best. Erik

Hey Erik,

This is just a super simple example to show what's possible.

The timer is only set to 10 seconds for demonstration purposes.

Apple Mail is the target app, since I don't have your sound app – and the exclusion list is a regular expression.

-Chris


Activate an App after a Given Amount of Time if Other Apps are Not Frontmost v1.00.kmmacros (8.7 KB)

Macro Image

Yes it’s possible. I am certain there are more elegant ways to to do than what I’m about to suggest, but a simple way to do this would to create a macro that is triggered when the app deactivates (loses focus). It’s only purpose would be to record to a variable the time that the app was deactivated and then enable another macro that has a periodic trigger (say every 15 seconds, or 1 minute), that can check the variable, compare it with the current time, and if it’s been 3 minutes or longer, bring that app back to the front. Then the macro would disable itself to prevent it from running continuously.

When I’m back at my computer tomorrow I can provide you an example of how to do this if you’re interested.

@ccstone beat me by mere seconds and I’m certain his suggestion is better than mine anyway :sweat_smile:

Great!! Thanks both of you! I'd love to understand how the text %Application%1% and matches works. How can this text point to the actual apps?

Any way. Its easy enough to change all the parts in the macro... Thanks again for sharing your knowledge!

All the best. Erik

Tokens user manual section.

1 Like