It has nothing to do with AppleScript. You just have to put the macro in a group enabled when you want to run it. For example if you wanted to run it when Safari is in front, then it would have to be in a group enabled when Safari is in front, or in a global group.
Couldn’t I make some simple Applescript application that does basically nothing. Run it, and use the “Triggered by ABC Application” to kick off the KM macro?
You could, but there are better ways: if you click on “or by script” in the triggers area of a macro and select “Or by AppleScript”, KM will display the command to run from AppleScript to trigger the macro. Using this method you can trigger a macro by clicking an icon in the Dock, for example, but you could also combine it with Folder Actions to trigger a macro when the contents of a folder changes, etc.
I gotta say, the “dump app” solution seems really slick.
I just made an app called VPN400 to kick off a toggle method, and it does basically nothing.
Now, for any KM I want, I can just
(1) duplicate the dumb app,
(2) rename it to the new app for kicking off the desired KM script, and
(3) within the desired KM macro, use the “Triggered by” function so that the dumb application kicks off the macro.
Obviously, this is a bit of a disjoint approach, without a lot of smarts or flexibility, but it seems to get the job done for simply kicking off a script.