Getting the Status of a Macro

Hi guys. I've got a macro that toggles the status of another Macro Group. Since the status of the group toggles, I'd like to set up a notification that immediately tells me the enabled/disabled status of that macro group, but I can't seem to find it.

In this case, I've tried quite a few tokens and none of them seem to be able to show the status of the Macro Group.

What am I missing?

thanks.

In theory, one ought to be able to do this with AppleScript:

tell application "Keyboard Maestro" to get enabled of the macro group named " Media Composer Number Keys"

However, I've noticed a little bug whereby toggling the enabled/disabled state of a macro group using the toggle action doesn't update the Keyboard Maestro UI. Therefore, whilst the macro group is indeed disabled, for example, it will still appear in Keyboard Maestro to be enabled, and AppleScript will thus report it as being enabled.

As a workaround, you could use AppleScript to replace the toggle action:

tell application "Keyboard Maestro" to tell the macro group named " Media Composer Number Keys" to set enabled to not enabled

then use the same AppleScript from the first snippet to retrieve its enabled status.

Hi @peternlewis. Above is a description of what I believe to be a bug, which is how I framed it when describing the situation to another user. I have since been prompted to alert you to the potential problem, which I neglected to do the first time.

I cannot duplicate this. If I use the Toggle Macro Group Enable action to toggle the group, the macro group toggles enabled/disabled as expected, and the response to the AppleScript request toggles as expected.

Maybe there is an issue communicating between the editor and engine on your Mac (the Assistance window should show that as an issue if so).

so, back to my original question that started this thread. Is there in fact a notification built into Keyboard Maestro (not AppleScript) that has the variable of the status of a Macro Group?

The “activation” status? Not directly, it is a transient state, so the Keyboard Maestro editor doesn't know anything about it.

You can infer the activation status of a macro group based on the activation status of its contained macros, which in turn can be inferred from the results of the “gethotkeys” AppleScript command in the Keyboard Maestro Engine dictionary. It only lists macros that are currently active, so if a macro appears in there, then the containing macro group is active.

1 Like

Hi Peter,

Thanks for taking the time to respond. Much appreciated.

It's puzzling, though. You say that Keyboard Maestro has no idea about the activation status of a group of macros. But if a group of macros are disabled, inside of the editor, the UI displays that group of macros as shaded. And when those macros are active, the shading is gone. So, doesn't KM have to know the status of that group of macros to be able to decide whether or not to shade it?

You are conflating “activation” which is a transient state, with “enabled” which is a semi-permanent state.

A macro can be enabled or disabled in the editor, and this shows in the editor.

A macro group can be enabled or disabled in the editor, and this shows in the editor.

A macro group can have a set of activation conditions (the most common example being when a specific application is at the front) as configured in the editor. The engine activates or deactivates the macro group according to the activation conditions. The activation status of a macro group is not visible in the editor (or engine). A macro group can be active only if it is also enabled.

A macro is active if it is enabled, and if its parent macro group is enabled and active.

I trust that is clear - Keyboard Maestro (editor) will show you the enable/disable status, and you can get that via AppleScript, but the transient activation status is not shown or available.

Thanks for that tip. I was able to make a quick AppleScript using your command, save it to the desktop, and call if from within Keyboard Maestro. Then I could assign it to a variable. All good.(I'm just learning AppleScript.)

I'm curious how you knew that you could extract that particular variable through AppleScript, and how you went about crafting that command. I'd like to start doing AppleScript a bit more but it seems impenetrable.

Every language seems impenetrable at the start. Learn by doing, and I assure you, it gets easier.

To know what commands are available for a particular (scriptable) application, refer to my response here:

plus @ccstone's:

His method for accessing an AppleScript dictionary is simplest, so go with that. But I reference my post also because it gives a little bit of an explanation about what an Applescript dictionary is; and it also tells you about the Library window, which—once an application's dictionary has been accessed in Script Editor once—-becomes the route through which you access its dictionary in the future (you don't have to keep dragging the application file to the dock icon each and every time).

Here's a screenshot of the pertinent bit of the Keyboard Maestro AppleScript dictionary that gave me a helping hand:

Firstly, it tells me there's an object called a macro group, and this contains other objects called macros (pretty easy to discern what those are). Secondly, it tells me that every macro group object has a property called enabled that is a boolean (true/false), and can be both read (get enabled of...) and set (set enabled of...), since read-only properties (those that cannot be set to something else) have r/o next to them.

Though looking at this now, I see a property called disabled on this Mac that I've never noticed before, and has my interested piqued. I think I'll experiment with that a little later and see what that's all about.

Thanks! That's a good start for me. I'll play around with this some and also search out some tutorials on AppleScript. It looks like a great addition to the powers of Keyboard Maestro.

Umm, apparently Keyboard Maestro is more powerful than even I remember. You can test the activation status of a macro or macro group using the Macro condition.

1 Like