Automatically Sort Macros According to Containing Group

Howdy folks, this post by @82Taylor inspired me to make this macro.

It's designed to automatically change the sort option when switching between macro groups. For instance, I have several smart groups such as "created in the last week", "used in the last two minutes" etc. In those groups, I like to have the macros sorted by "creation date" and "use date" respectively. This macro detects when Keyboard Maestro's window title changes, and sorts the macros according to the group I'm currently in. The IF action ensures it only runs when the group column is clicked on. That way, when you click on a macro inside that group column (and the window's title changes again), it does not trigger and resort the macros again.

End-user modifications would include setting the string to whatever your groups is called for each "contains" switch, and then selecting the appropriate sort option in the Select Menu Item action below.

It's fairly straightforward, but if anything is unclear, or if you have suggestions as to how it can be improved, don't hesitate to reach out here or in a PM.

-Chris

CURRENT VERSION: 1.3.1 (Monday, February 07, 2022)

v1.3.1: Monday, February 07, 2022
Added a condition to only trigger if the front window is the Editor.
This prevents it from triggering if you have the Macro Inspector or other such window open.

Previous release notes (click to expand/collapse)

v1.3.0: Saturday, December 25, 2021
Switched to local variables so as not to clutter up end-user's variables list.

v1.2.0: (unknown date)
I added an AppleScript to determine if the macro's title field is currently focused and if it is to abort the macro. This will prevent the macro from needlessly running when all you're doing is changing a macro's title.
While it still triggers and then runs the AppleScript, it does significantly cut down on lag while editing a title.
As always, I am sure this can be improved on, and if anybody has suggestions of a better way of doing this, please feel free to let me know. :grin:

v1.1.0: (unknown date)
Added an IF action to ensure the macro executes only when selecting a macro group.

v1.0.0: Saturday, November 27, 2021
Initial macro

06)[AS-KM] Macros- sort according to focused group.kmmacros (33 KB)

Macro screenshot (click to expand/collapse)

3 Likes

Hey thanks!

Added your Menu condition and it works perfectly – hadn't thought of a solution for that yet!

Cheers!

1 Like

Thank you! I edited my post to give more credit where more credit is due haha. I don't know if I would have thought of this if it weren't for your post. Glad the IF action worked for you! :grin:

1 Like

Updated to version 1.2, with the inclusion of an AppleScript to prevent the macro from fully executing if you're in a macro's title field.

See post #1.

Howdy folks, version 1.3.1 is out (apparently I forgot to post 1.3.0 but oh well :laughing:)

See post #1.

1 Like

@cdthomer, this is great and opens up some other creative possibilities. Gears are turning...

Thanks for sharing!

1 Like

Chris,
I have tried that macro but I wonder where does this script come from ?

1 Like

Whoops! I use compiled scripts on my personal versions (but have the AppleScript itself in the action)... try switching script file to text script and see if it pops up for you. Either way I'll update the macro in post 1 in a minute. Sorry!

EDIT: @macdevign_mac post 1 is updated with the corrected issue. If switching from script file to text script didn't work for you just download again. Thanks for alerting me to this! :laughing:

Chris,
I see. Thank

1 Like