How to set a keybinding to enable/disable action / multiple actions?

I want to make ⌃ + D a keybinding that would enable selected disable action/actions. Or alternatively disable selected enabled actions.

I can’t quite figure it out since the menu bar title changes if I select more than one action. How can I account for that?

I believe it was working for me before KM 8 but something happened and broke this. :disappointed:

Counting the selected actions (new AS support in KM8) and modifying the name of the menu item you’re looking for might work. Have to run atm but will toy with that idea when I get back.

Luckily for you, I made a macro to perform this exact function just earlier today, as I also had a similar setup in 7+ and earlier and quickly missed it upon upgrading to 8. There are surely other ways to do this (I saw one solution by the inimitable @ccstone that used GUI scripting) but so far this method is working well for me. (You will of course need to change the shortcut to one you prefer, but that should go without saying at this point :wink:)

Enable:Disable.kmmacros (2.3 KB)

19 Likes

Oh wow. That is amazing. :yellow_heart:

Glad gglick is taking place of inimitable @ccstone while he is away.

1 Like

Glad my rudimentary regex knowledge could help! I have a long way to go before I can stand alongside @ccstone, but thank you very much for the comparison :smile:

As I said, this has been working fine for me so far in limited testing, but if you (or anyone else who makes use of this) runs into any instances where it doesn’t work, please let me know so I can fix them.

Aw man! That’s much easier than what I was thinking. :slight_smile:

Woah! And this does actions, macros, and macro groups! Awesome!

2 Likes

You’re not alone in thinking of trying the new AppleScript functionality first! That’s exactly what I first looked into as well, but my AS knowledge is even more rudimentary than my regex and it was over my head to come up with a solution that way. Luckily the easy solution seems to be working okay so far :wink:

Yes I opened the Keyboard Maestro dictionary in Script Debugger and set to tinkering… but I think we’re at about the same level of AppleScript competency :joy:

I figured out how to identify the macro I’m editing, list its actions, and was working on identifying & counting just the selected actions (to search for Enable/Disable X Actions menu item) when I saw your solution.

2 Likes

This Regex is so cool @gglick ! Makes me want to find more use for regexes in my work, haha, amazing :thumbsup:

2 Likes

Thank you!

1 Like

@gglick Thanks for the macro! I didn't realize one can use this method to select a menu before. May I ask what the language of this? → ^(?:Enable|Disable) (?:\d+ )?(?:Macros?|Actions?|Macro Groups?). It look like regular expression but it uses space instead of \s.

@Alice_Shi You're welcome! This has been one of my own most useful macros when working in the KM Editor, so I'm glad it's proved useful to so many others.

To answer your question, it is a regular expression, just one that uses a typical space character. \s is handy for when you want to match any and all kinds of white space characters, but if you know you just need to match a typical space, there's no reason you can't use it in your expression.

1 Like