Subroutine to Get List of All Macros and IDs in a Specific Macro Group

A KM user recently asked about getting a list of all the macros in a specific macro group in order to create a pick list to simplify choosing one macro out of the many they had in their KM environment. As it happens, the solution to their request was already built into KM but I had the thought that generating such a list might be useful in other use-cases. so I created this KM subroutine to do just that.

[SUB] Get List of All Macros and IDs in Specific Group

Inputs:
Local__Macro_Group: The name of a KM Macro Group
Local__Delimiter: separator between each UUID and macro name - by default ","

Output:
A list of the UUIDs and names of every macro in the specified Macro Group in the form:
<UUID><Delimiter><name>
<UUID><Delimiter><name>
etc.

Here's the subroutine:

Download Macro(s): [SUB] Get List of All Macros and IDs in Specific Group.kmmacros (6.4 KB)

Macro-Image

Keyboard Maestro Export

Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System Information
  • macOS 13.6.1
  • Keyboard Maestro v11.0.2

And here is a simple macro that tests the use of the subroutine on the global macro group, uses the generated list in a Prompt for the user to choose and then runs the selected macro:

Download Macro(s): Test [SUB] Get List of All Macros and IDs in Specific Group.kmmacros (3.5 KB)

Macro-Image

Keyboard Maestro Export

Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System Information
  • macOS 13.6.1
  • Keyboard Maestro v11.0.2
5 Likes

Hello Taj (@tiffle)

Thanks for sharing this useful Subroutine…

It makes it so much easier now getting all Macros of a specific group…

another thing I don’t have to build on my own - again many many thanks :pray:

Greetings from Germany

Tobias

1 Like

You're welcome Tobias - hope all's well :grinning:

1 Like

Yeah, not all but it gets better from day to day … let’s say I am happy to be back in the game after months of all kind of trouble, hassle and not being able doing things I love to …

Greetings from Germany

Tobias

1 Like

hello @tiffle !
my apologies for the delay. Your macro is fantastic. Extremely useful. My problem is that it works with some macros and others not.

KBM Engine: 2024-02-21 16:52:46 Action 15561165 failed: Execute an AppleScript failed with script error: text-script:150:169: 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)

I suspect that it has something to do with the fact that macros have to be active. To test this hypothesis, is there any way to modify the macro so that "enabled" macros is enough (the macros don't have to be active) ?.

Again many thanks. I will be a big user of this macro. You should get a royalty every time I use it.

Hi Ronald,
I've just done some testing and I cannot reproduce your error. I've tested with enabled/disabled/active/not active macro groups and macros and I never get the error.

I notice though that the error you've quoted occurs when the AppleScript is getting the name of the macro group that you are passing to the subroutine. I can only guess then that there is something unusual about the names of some of your macro groups.

Can you perhaps show me the names of some macro groups that cause the error to occur?

1 Like

thank you for your prompt answer.

3 examples of problematic macro goup names below.

Common Operations - Files
Common Operations - Reddit
Common Operations - MEDICAL

thank you

did you test if it works if you want to trigger a macro within a palette which you would normally display with a keyboard shortcut ? If you did not use a keyboard shortcut to display the palette, the macros should be inactive and your get list macro should not work ?

I've just realised what is causing the error: I thought you were complaining about the subroutine throwing the error, but in fact it's the test macro that has the problem specifically in this action

image

This line is trying to execute the macro you chose from the prompt list

do script macroUUID

and of course you can't execute a macro that is disabled or in an inactive group etc. etc.

It's my fault that to demonstrate the use of the subroutine I chose to prompt the user to choose a macro and then (to prove it was chosen) run the chosen macro. Maybe I should have just displayed the choice. I hope you understand that this test macro was just to demonstrate the use of the subroutine to produce a list and then it's up to you what to do with that list.

So - to avoid the problem, in the test macro you have to put in checks to make sure that when you have the list you only do sensible things with it.

I can't spend any time on doing that for you at the moment - maybe you can give it a try as it's going to be a few days before I can look at it again. :frowning_face:

1 Like

thanks very much. I will try to figure it out.

1 Like

I know that you are busy and you have been extremely kind. May I just ask you if this workaround makes sense.

Common Operations - Reddit is a palette triggered by a keyboard shortcut, which means that the macros are not active if the palette is not displayed.

All seems to work fine now. I have not encountered the error messages.

Yes or No and only if you have time. Just in case this would save you time if and when you look into the issue in the future.

thanks very much

That's a very creative way to address the issue Ronald but it does suffer from one drawback: it will always leave the specified macro group in a deactivated state regardless of the state of the group to start with. So you really only need to perform the activate/deactivate if the group's initial status is "deactivated".

Since I don't know exactly how you're going to use this, it may be that you're always using it with deactivated groups - in which case there's no problem and your workaround is perfect; otherwise some extra tweaking is needed to be a bit more generally usable.

If you're still stuck on the extra tweaks when I come back I'll be happy to take a look :grinning:

1 Like

Yes, that's precisely the case. Macros in palette triggered by a keyboard shortcut which by definition are deactivated.

For active groups like my global macro group, I use your original macros which work fine.

So all is great and thanks a million !

1 Like

This is working well. I was trying to take your warning into account re active / non active groups.

2 Likes

Good job, Ronald :+1:

1 Like

Hi @ronald
I saw your post in the other thread about the "glitch" you are experiencing with the deactivate action.

Have you tried putting a Pause action just prior to the deactivate - maybe 0.2 seconds? I don't know if it will help but I guess it's worth a shot :wink:

1 Like

I will do it. thanks very much

hello @tiffle
I am using the macro a lot and can't resolve a minor issue. The list often displays at the center of my screen and overlies the document I am working on.

I am trying to move the display of the list to another part of the screen.

I tried inserting the move and resize last engine window action, but it does not work. Would you have any ideas ?

thanks very much !

Hi Ronald - Personally I would use the Set Next Engine Window Position action just prior to the action that displays the list.

KM wiki: action:Set Next Engine Window Position [Keyboard Maestro Wiki]

If that doesn't work you might be running into the window-positioning problem that's been discussed a lot here in the forum - but is generally related to Sonoma (and maybe Ventura). The approach to that seems to be to repeat the window-moving action 2 or 3 times one after the other. Once again I'm without my Mac so I suggest you look at the results of this forum search for further ideas - Search results for 'Sonoma window bug' - Keyboard Maestro Discourse

Hope that helps!

1 Like

works perfectly. You are a genius @tiffle !

Special request for @peternlewis

With the move and resize last engine window, I often (always) use the Get button. It is much simpler than calculating coordinates. Greatly accelerates workflow.

Wish list: add move and resize with the get button to the "set next Engine Window Position and Size" action. Thank you @peternlewis !

1 Like