Macro Group - app specific

Been using KM for a year or so now and never had issues with the groups (not that this is a KM issue anyway). Today I noticed that I got an error when a macro was supposed to run, triggered by Hazel. Since Finder was not the front most app at the time and that group is specific to Finder, I got an error.

So I went to the wiki page (Macro Groups [Keyboard Maestro Wiki]) to check what it says.

Up until now, and because I never encountered any situation where this would show me an error, I was convinced that when assigning an app to a group (Finder, for example), it was more related to things triggered directly by the user, or things that actually needed the window to be visible, and then things that can happen "behind the scenes" would still run, for example if a macro would use an AppleScript to rename a folder, or move it somewhere. I'm not an expert on either AS or Shell, but I believe that these can run without the app they are targeting being visible, right? If so, I thought KM would be the same way, but I guess it's not?

Can you please confirm that any macro that's assigned to a particular app, regardless of what's inside (action wise), needs that app to be the front most app? Or are there any exceptions? If so, which?

Thanks!

Are you talking about macros in groups that are defined by the "Available in these applications" menu for the group? If so, then yes, those macros only run when those applications are frontmost—at least, that's my understanding of what that restriction does.

If you have macros you want to run from anywhere, put them in a group where there's no application restriction. If the macro is an AppleScript designed to work in Finder, more than likely it's got code in it to directly work with Finder, so it shouldn't care if Finder is frontmost. (And if it did have to be, activate application "Finder" would probably do the trick.)

-rob.

Yes, that's what I mean.

That's what I've been doing, and maybe because all my macros are either done manually via a shortcut or they have the "activate application" action, I've never experienced that error until yesterday.

I haven't tested with a macro that only contains AppleScript. This particular macro is just a few "normal" KM actions to rename some files, no AS alone.

I think this is the perfect scenario where having Folders instead of just Macro Groups could be handy. I could have a folder called Finder (instead of a Macro Group) and inside I would be able to have multiple macro groups, all focused on macros for Finder, but where some are "global" and some are "application restricted".
Since that isn't possible, now all macros that are application specific, but I want to run in the background, need to go to a global macro group, making that group a huge mess.
Everything could be well organized if folders were implemented. Unfortunately that doesn't seem to be something that will be implemented, according to a thread someone started a while ago and Peter doesn't seem to see the value of that.

Thank you for answering my question and clarifying that for me.

No. AppleScript can only execute macros that are currently active.

I was talking about AS and Shell outside KM.
For example if I have Script Editor with a script that renames a Finder file, even if Script Editor is the front most app, I can run it and it will do its thing. The same with Terminal.
I thought some KM actions would behave the same way, allowing them to run in the background even if the targeted app was not the front most.
But I see it's not how it works. No problem. I will put them in the global group.

FWIW, if it helps you organise things, there's nothing to stop you having two Finder groups, one with app specific permissions and one with All Apps, as long as you give them different names (e.g. Finder - Global or similar). You won't then have the one global group overflowing with macros, and it should be easier to find things.

1 Like

Sometimes I use more than 1 group as well for certain things, but I avoid it, because if we start duplicating groups, we end up with a lot of them on the list.
image

Having a folder with all the groups would be better for keeping everything nicely organized and less cluttered.

That depends on the action. Some actions can operate on background applications, most target the foreground application.