I needed to retool macros that use app launch triggers

EDITED - SOLVED - I'm leaving this up in case someone else bumps into the same problem.

I have a pair of macros that trigger when any app is launched or quit. The macros look in a designated folder for a notes/cheat sheet file named after the app. If a notes file exists in the folder, the macros open the notes on launch, and close the notes on quit.

I was using the trigger value from the app launch/quit to search for the notes file.

Recently, the macros stopped working. They didn't trigger. It's because KM has changed the trigger value it returns when an app launches or quits. It now supplies the path and the .app extention.

To fix this, all I had to do was add two Search & Replace actions, one to remove the path, and the other to remove the extension. Now it works fine.

Thanks as always to the helpful folks on this forum.

You have submitted great screen shots. I'm looking at it. But I'm just an average user, not one of the elite troubleshooters here.

If you are willing to try something that has worked for me, which might fix the problem, create a new macro group, drag these two macros into that group, and try it from there. My theory is that there may be something wrong with the macro group, and when I do this it has sometimes helped me.

Thanks - the screen shots come from the Share menu in Keyboard Maestro. The availability shot was done by Snagit.

Some questions for info we need to troubleshoot:

  1. What changed on your Mac just before the macros "stopped working"?
  2. What versions of KM and macOS are you running now?
  3. Exactly what do you mean by "stopped working"?
    • Don't trigger
    • Give the wrong result
    • Other
    • Provide details and screenshots

As soon as I posted, the answer presented itself. KM has changed the way it returns the application name when triggering from an app launch. It used to return the app name only, like TextEdit. Now it returns /Applications/TextEdit.app.

I just needed to add a couple of Search & Replace Clipboard actions and strip out the app name.

Thanks very much. You're always very helpful. I'm going to edit the original post.

Good job. That would have taken me a while to figure out.

You can also get the name of the FrontMost app using this KM Token:
%Application%1% token

Hey, thanks! That's even better.

1 Like

I searched for the release notes for KM9 and it does provide a related warning: (see yellow text below which comes form that page)

* Changed Application trigger to set TriggerValue to the path of the application. (may break macros)

It sounds like this may have been your issue. If so, I wonder if future release notes could put anything that explicitly "may break macros" into a special section of the release notes so that it's brought more prominently to our attention. At least the release notes do say "may break macros" which is very honest and helpful. but maybe a little more prominence is needed for us.

I will even go one step further and suggest that any actions which are changed by a KM upgrade in such a way that they "may break macros" should be automatically highlighted in red (or maybe a unique colour) so that we know there could be a problem. If I saw an action highlighted in some odd colour (say red/blue stripes) that would sure get my attention. And I could easily set the colour to normal once I validate that the action still works.

1 Like

FWIW, I applied this, but I found that when an app is launched by KM, the %Application%1% token doesn't reflect the last launched program very quickly. This resulted in the wrong cheat sheet being opened when KM launched the app.

Rather than slow the process down with pauses, I went back to removing the app path using Search and Replace, which works well and quickly.

Thanks for the suggestion, though. I think %Application%1% token will come in handy in other situations.