Select Macro Group or Smart Group

I am sure it is on this forum somewhere but I am not finding it. Is there a way to select a macro group or macro smart group with a specific name like "-All Macros?"

Short answer: yes. Long answer: the best solution involves using AppleScript to talk to the KM Editor application. I took a stab at it (30 minutes of struggling) but failed. It should look something like this: (my sample folder name is "BUGS")

Hi, @skillet.

Once you have the group UUID, you can use the Open a URL action:

Here's a macro that finds the UUID and then selects the Macro Group or Smart Group.

The two Execute a JavaScript For Automation (aka, JXA) actions could be easily combined, but I left them separate to make it easy if someone is only interested in one of the group types.


Download: Select Macro Group or Smart Group by Name.kmmacros (12 KB)

Macro-Image


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 15.3 (24D60)
  • Keyboard Maestro v11.0.3

2 Likes

Thank you for spending so much time on that!

This is vey impressive and so helpful! I will use this many, many, many times per day and something I have wanted to do for years! It is very quick too!

1 Like

You can also use the name -- remembering to URL encode it if necessary. Oh -- and hope it's unique!

Then you might find the other "URL Schemes" items useful...

And because, IMO, no thread is truly complete without a bit of AppleScript :wink:

-- You can also use a UUID instead of a name
tell application "Keyboard Maestro" to select macro group "Tests"
1 Like

Oops, yesterday's version had a typo.


Not sure how that happened because I remember testing it. :thinking:

I've corrected the error and uploaded Version 1.1 of Select Macro Group or Smart Group by Name

Thanks for showing exactly what the type was it helped me update about a dozen macros that I made that use this. That is even better and has it selected so you can go straight to the arrow keys.

Your skills at making this macro are amazing and I personally don't even know how to process it though I have looked through everything. I am in awe and grateful to be able to have this and use it. I have used it over 100x already today.

I am very fearful to ask this because it is too soon but it might be the better time to ask this while it is fresh on you mind. I really wish I knew how to manipulate this or to be able to upload it to AI to do find out how.

Is it possible to have it select multiple macros at once. For example I have several macro groups that are used for just Keyboard Maestro. I tried comma seperating, using return, the pipe, etc. No worries at all if not because I am a super happy camper with what you have built this is amazing and will be used many times every day I am on my computer using Keyboard Maestro.

1 Like

Not to my knowledge, but maybe someone else on the forum will suggest a method.

You're jumping between macros and Macro Groups. What do you actually want to do?

The general pattern would be to make a list of items that match certain criteria and select them. For example:

tell application "Keyboard Maestro" to select (every macro whose name contains "Scratch 3")

...or...

tell application "Keyboard Maestro" to select (every macro group whose name contains "Test")

...and I'm sure someone who knows JXA could change the name-check from "exactly matches" to "contains".

1 Like

Thank Jim, your macro is very handy! It also allows me to select Smart macro groups which is what I initially needed the most.

The second one did just what I wanted to but I can see some good use cases for the first AppleScript. Thank you very much, it will allow me to work and sort and find things quicker for different applications that have different group settings.

I tweaked the second slightly to give me only macro groups that are active.

tell application "Keyboard Maestro"
  select (every macro group whose name contains "Keyboard Maestro" and enabled is true)
end tell

Here are a couple of macros that will select the active macros with a prompt as well as the macros with the name in it based on the current system clipboard (which you can type in your own name if nothing is in the clipboard).

**AAA - Automation - Keyboard Maestro Macros.kmmacros (59 KB)

I tweaked the second slightly to give me only macro groups that are active.

Forgive me for noting the words "active" and "enabled", but I recently demoed a macro that hinged on a distinction between the two words, so they sort of popped out at me.

If it's actually the list of groups that can activate/deactivate depending on group settings and the app you are working in, you want you might want to give this macro a try.

(If it is indeed all the enabled groups, including those that are not active, that you're after, nevermind...)

A prompt list presents active macros or groups and selects your choices in the editor.

It allows multiple selections.

It now has an option to append Smart Groups when the macro groups option is set.

Other options include listing all active macros or just those with hot key and typed string triggers.

The instructions contain more details.

Active Groups Or Macros in Prompt List -multiple selections v 02.kmmacros (16.8 KB)

2 Likes

Yes, enabled would have been a better choice of words. That just means (as you are probably aware) macros that have their triggers enabled which can be run by other macros within Keyboard Maestro if the macro is disabled or the group is disabled but not by calls of AppleScript.

If I understand you right and what you macro is showing is macros which don't show a target of just a single application and are open in every application.

-- ignoring application responses
tell application "Keyboard Maestro Engine"
  do script "4975B245-A347-44A6-8153-FD5ADF7CB9EA"
  -- or: do script "Communication - Change Back to Scrivern Formating C4"
  -- or: do script "4975B245-A347-44A6-8153-FD5ADF7CB9EA" with parameter "Whatever"
end tell
-- end ignoring

"If a macro is disabled, or is in a disabled Macro Group, it cannot be triggered under any circumstances."

https://wiki.keyboardmaestro.com/Macro_Activation

This statement is slightly deceptive since you can call it from another macro action that calls it. You can not call it via AppleScript though. I think added clarity on the Wiki would be helpful talking about this since naturally one would beleave that it can't be called on either.

Then there are these two macros
image

I am really trying to get my head wrapped around all of these things and spent a lot of time experimenting and reading the Wiki and Forum.

I'm sorry if I muddied the waters on this one. :man_bowing:

I probably should have said something like, hey, others have offered fine solutions, would this supplement your needs? Instead I sounded like I was nitpicking on active vs. enabled distinctions--which I am not always clear on either. :wink:

This might help in deciding if this macro can be of use to you.

The prompt list source is primarily from the AppleScript "gethotkeys" command in the Keyboard Maestro Engine Suite. I added the option to append the Smart Groups you mentioned.

Whatever "gethotkeys" decides is an "active" macro is what appears in the prompt list.

The scripting defintion puts it this way:

gethotkeys (verb) Gets an array of groups of arrays of macros that are currently available via hot keys or typed string triggers. (from Keyboard Maestro Engine Suite)

The optional getall parameter: "retrieves all active macros, not just hot key and typed string triggered ones"

The macro allows for setting the getall parameter to true or false.

I'm afraid I don't know how availability of macros to AppleScript plays out in gethotkeys's rules of inclusion--but am curious now.

But here are a couple of ways to check what gets included:

The count of of macros/groups is displayed in the prompt list In the case of macros, either a count of those that have at least one of the 2 types of triggers described or all that the command considers active, if you have set the getall option.

The items shown by Show Active Macro Groups menu of the Keyboard Maestro status menu are fairly close to what gethotkeys shows, I believe.:crossed_fingers:

FWIW, here is the post that prompted the demo.

Summary

How to list current active macro groups - #12 by dtremit

If the macro doesn't suit, nevermind...

If it sort of fits, but needs adjustments, I'll rejigger what I can within what gethotkeys can do, such as getting a subset of "active" macros by typed string trigger or hot key.

Thank you for sharing this and the explanation, if there is any regiggering I will do my best on my own. I appreceate you sharing all that.

Giggity.

1 Like

(Emphasis mine.)

The Wiki is literally correct. A disabled macro, or a macro in a disabled Macro Group, cannot be triggered -- it doesn't say that it cannot be executed.

Don't conflate "trigger" and "execute". Don't conflate "enabled" and "active". These aren't "a better choice of words" -- they're terms for different, and key, concepts.

Keep them separate in your head and you'll be able to make sense of what you see in your experiments.

1 Like

Absolutely, I agree, and that is why I said it is slightly deceptive. We have been on here for hours and hours and it takes almost a degree to get all these things down. It would not be a trigger if you called on a macro via AppleScript, but if a macro is disabled via the trigger, it can not be called upon. I have chosen to implement this to help me call macros that way, but it is also not consistent based on the logic.

Yeah, the active really confuses me even after a lot of experiments. You can make a macro inactive via a macro action only from what I can tell but there is no indication in the editor. Yet you can still call on macros in the inactive group so it doesn't quite make sense all the use cases after a lot of reading but of course it solved a need that I am not quite seeing here.

Thanks for your reply. I do think it would be helpful in the Wiki to state these exceptions and clarify the words. It may be there somewhere on the page and I have just missed it.

Please show us the action that does this, so we can try it ourselves...

I am not doing so well with wording right now. This should have read Macro Group not macro.

This is what doesn't show any indication that I can find if it is active or deactivated. I am not sure how you tell and getting my head wrapped around the purpose of this is not clear.

https://wiki.keyboardmaestro.com/action/Activate_Macro_Group?redirect=1

"Remember that all macros within a Macro Group that is not active will not be available for use."

I am thinking this means by showing a pallet or something. They are available for use to call on the macros in that group from another active macro group just like when you don't have a macro group or macro enabled. So it seems like calling another macro that you don't want to be able to be executed from another macro if you want it disabled is via AppleScript. Plus, with the Enable unchecked versus dong the "Deactive," you can at least see the macro group or macro greyed out.

I hope that is more clear. I am sure I am missing something key here.

Why do you need to know if a Group is active or not?

A Group's activation status is transient and, generally, contextual -- availability by frontmost app, focused window title, etc and then the explicit activation options. The "Activate Macro Group" action allows you to select those explicit activation options programmatically.

You know your current context, you know if you've used on of the activation options. If you really want to know if a Group is active or not you could use an "If" action with the "Macro Group X is active" Condition. How would constantly updating the KM UI, with the significant overhead that implies, help?