Application and Window Activation Triggers Don't Work

I cannot activate macros with application or window triggers.

Here is a simple example:

  • This macro is in a group that is active in all contexts, but never fires.
  • I have tried it with multiple applications and nothing works.

1 Like

Any time a macro does nothing, start by trying the Interactive Help (Help menu, Interactive Help), and choosing the option for Something expected is not happening.

It will tell you why the macro is not firing, or whether it is firing - sometimes it seems a macro is not firing when in reality the macro is firing and the actions are doing nothing, as could be the case here if the System Notifications settings have disabled Keyboard Maestro’s ability to notify.

1 Like

Thanks Peter. That's an impressive resolution engine. It was in fact notifications.

If I might ask a followup – I am trying to make this work with a window activation. I can get it to fire with "focused window changes". However, it's running twice. Can't seem to figure out how to debug this.

This is the whole macro. It does the text type step twice.

Cheers,
MBS

As part of the diagnostic process it's always a good idea to look at the Keyboard Maestro Engine Log:

~/Library/Logs/Keyboard Maestro/Engine.log

Thanks Chris. Here is what I see in the log. As we can see here it's definitely running twice. Any idea why?

When the window became active
2023-06-02 14:36:22 Execute macro “VPN” from trigger The Focused Window Changes
2023-06-02 14:36:22 Execute macro “VPN” from trigger The Focused Window Changes

When the window was closed
2023-06-02 14:36:28 Execute macro “VPN” from trigger The Focused Window Changes
2023-06-02 14:36:34 Execute macro “VPN” from trigger The Focused Window Changes

Some further information that might be relevant.

I tried to work around the issue by backspacing to remove any existing text before inserting, as below. It does not solve the issue. The text "test" still gets inserted twice, which makes me think that the two instances of the macro are running simultaneously somehow.

However, I noticed something interesting. This double firing only happens when the window is first raised. If I click out of the window and back in, it only fires once.

It's possible there are two changes. Maybe there is some invisible window that is involved, it's hard to say.

The solution is to deal with the two successive changes.

For example, start your macro like this:

  • Semaphore Lock "My Window Check", with a very short timeout and abort without notification on timeout.
  • do your stuff
  • Pause a short amount of time (long enough that the semaphore lock of a successive macro will time out, short enough that it wont stop you checking another window).

Ah, I get your point. It seems I can simplify even further just by clearing out the stack as soon as the condition is met.

This worked (below). Thanks a lot for your help!

It's generally a Bad Idea to "Cancel All Other Macros" when there's another solution available -- it may work now, but in a couple of month's time when you've written some macro that do things in the background you'll be pulling your hair out when they mysteriously abort...

Try @peternlewis's suggestion of a "Semaphore Lock" instead. Used with a short timeout (and, from the logs, you only need 0.2s to be safe) the second window change will still fire the macro again, but the second instance will self-cancel and not interfere with the first.

It's an image of the whole macro, which means that anyone helping could be missing important information -- such as any options you may have set on the actions. Best way to get help is to post a slimmed-down version of the actual macro, including what's needed to reproduce the problem but removing/changing any fluff or "sensitive" stuff. Instructions on how to post a macro can be found here.

2 Likes

Thanks @Nige_S - will use that if I need help again. I was able to achieve the result with a Semaphore Lock initially, so I'll revert to that.

Cheers!

MBS

2 Likes