Call KM Macro by Name?

I asked awhile back how to call a KM macro from the Shell, and I was told to find the Macro number and use that. I found recently it was possible to use the Macro name itself, which is great!

I'm curious as to why that was not mentioned to me before. Is it a recently-added feature?

If you use UUID, you do not need to edit your scripts if you change the macro name, which happens a lot to me.

If you use macro name, you will have to update your scripts whenever you change the name of the macro. Macro names have the advantage of readability though.

This is the biggest difference as far as I know, and it is a very important difference.

@gmark You are kidding right??? :rofl: I have a secret to tell you... There are a slew of things that I do, with Keyboard Maestro, that I haven't mentioned to the developer (@peternlewis ) either. Jokes aside, there are several ways to get to the same result and I've mentioned before that most likely even the developer doesn't know the full power of this tool. Good luck in your journey to learn all the nooks and crannies.

KC

2 Likes

Well, to change the name of the macro, I obviously have to put the new name in the trigger step, so what else is there to do?

Also, I'm told i have to "enable" the script, and that I can do that by selecting something in the "upper right corner of the macro screen.

But I don't see anything at all in the upper right hand corner. So how do I do that?

And how did this macro get "un" - enabled?

I've copied and pasted the macro name into the OSAscript, but it still tells me KM can't find it.

This is maddening!

And I'm still confused. If I change the name of the macro, and if I'm told the UUID does NOT change, why would KM NOT just update the macro name alone that's associated with that UUID and allow the new name to work as well?

Okay, I just copied the UUID for the macro and exported KMSCRIPT and executed in BASH:

KMSCRIPT="DC28CE9C-B823-4540-992F-7F10550DE689"

osascript -e 'tell application "Keyboard Maestro Engine" to do script "${KMSCRIPT}"'

AND the macro is in the list of Enabled Macros

AND the macro had been called and running fine using the ORIGINAL name it had for a long time but SUDDENLY started giving me THIS MESSAGE no matter how I called the macro EXCEPT by the assigned Keyboard Shortcut, =

46:69: execution error: Keyboard Maestro Engine got an error: do script found no macros with a matching name (macros must be enabled, and in macro groups that are enabled and currently active). (-1)

The enable/disable box is under the macro icon. E.g. (see the checked box below),
image

If you work in the Keyboard Maestro Editor, it does link the name with UUID. But since you are changing the name elsewhere, KM does not know whether you are intending to trigger the old macro whose name was changed to the current one, or that you want to trigger a new with this name. Whereas, the UUID is unique, and it does not change even you have changed the macro name. Therefore, using UUID is a better choice in most cases when you use script triggers. I hope this makes sense.

This error tells everything. It means there is no active macro with the given name macro.

Either the macro is disabled in someway (macros must be enabled, and in macro groups that are enabled and currently active), or a macro with that name does not exist at all (i.e., you may have changed the name of the target macro). Since you've been running it before and if you did not change the name, it's more likely that the macro is in the disabled state.

My guess is that KM only looks for the given macro name in the enabled macro list. If it does not find it, it gives the error report as you've seen.

@peternlewis, I'm wondering, when the given macro name is not found, is it possible for KM to continue to search in the disabled macro list, and when it finds it, it reports that the macro is disabled; if it does not find it, it reports that the macro with the given name does not exist. In this way, we have more clue about the error report.

It's always been like that. If you select the Or by Script at the end of the trigger, it will show you the code:

osascript -e 'tell application "Keyboard Maestro Engine" to do script "DDDDDDDD-DDDD-4444-8888-FFFFFFFFFFFF"'
# or: osascript -e 'tell application "Keyboard Maestro Engine" to do script "This Macro Name'
# or: osascript -e 'tell application "Keyboard Maestro Engine" to do script "DDDDDDDD-DDDD-4444-8888-FFFFFFFFFFFF" with parameter "Whatever"'

It gives you a variety of ways to call the macro, including by name or by UUID.

As others have mentioned, if you change the name, Keyboard Maestro cannot change your script, so the connection will be broken. You can also have multiple macros with the same name, even in the same macro group. These are the issues that the UUID prevents.

The macro must be active, which means it must be enabled, and the parent macro group must be enabled and active (note that in the case os using the UUID, I might relax that requirement, since the macro is being explicitly specified).

Sure. It's just code. The question then becomes which other feature on the todo list should I not implement to make time for coding this?

2 Likes

I can't see your to-do list. Even if I can see it, I don't know what is more important than others. I'll make suggestions if I think it is useful. This is not a necessary one (it probably does not bother me at all) but nice to have, especially for new users. But I trust you on deciding what features have higher priority. :ghost:

1 Like

Okay, guys, I thought I was following your instructions faithfully, but in reference to Martin's response, here's mine:

46:69: execution error: Keyboard Maestro Engine got an error: do script found no macros with a matching name (macros must be enabled, and in macro groups that are enabled and currently active). (-1)

This error tells everything. It means there is no active macro with the given name macro.

Either the macro is disabled in some way (macros must be enabled, and in macro groups that are enabled and currently active), or a macro with that name does not exist at all (i.e., you may have changed the name of the target macro). Since you've been running it before and if you did not change the name, it's more likely that the macro is in the disabled state.

My guess is that KM only looks for the given macro name in the enabled macro list. If it does not find it, it gives the error report as you've seen.

@peternlewis, I'm wondering, when the given macro name is not found, is it possible for KM to continue to search in the disabled macro list, and when it finds it, it reports that the macro is disabled; if it does not find it, it reports that the macro with the given name does not exist. In this way, we have more clue about the error report.

Okay I'm working in KM Editor, and after I read that I should look in the upper right corner for the "enable" command and then tried under the macro ICON, I got nothing.

Am I using the wrong version of KM ?

What version are you using?

Have you looked at the manual?

manual:Editor Window [Keyboard Maestro Wiki]

-Chris