I tend to use the command line for most anything like this.
In the current example:
- Select the macro of interest in a KM editor window
- Copy the XML for the macro with KM → Copy as → Copy as XML
- On a Terminal command line run
pbpaste | grep "<key>ActionUID</key>" | wc -l
The result is the number of lines containing <key>ActionUID</key>
in the clipboard, which is what you are looking for. Hit return and you have the answer instantly.
(Thanks @ccstone for the right XML tag to use.)
If you want a macro that will do it all with a hotkey:
Here is a fancier single-hotkey solution that gets the relevant information for the currently selected KM macro. "Currently selected" here means highlighted in blue in the KM Macros pane.
AppleScript queries application "Keyboard Maestro" for the name, class, and XML of the Keyboard Maestro selection. If the class is not "macro", then the AppleScript returns an error code of 1.
Otherwise the AppleScript runs the shell script given above to find the number of actions in the selection (along with an extra bit to strip leading spaces). The return value is a comma-delimited string containing the macro name and number of actions. KM will see this as a two-element array containing those values.
I'm sure that everyone contributing to this thread knows this, but others looking for solutions might not. A Mac is really a UNIX box with a bunch of very nice windowing and other capabilities layered on top. But when you open the Terminal application or use an Execute a Shell Script
action you are in a UNIX shell with the world at your fingertips. That brings with it a host of capabilities that augment/complement KM.
In the present context, UNIX has a suite of very powerful command line tools for text manipulation. These tools can get very complex. A couple are programming languages in their own right, as is the shell itself. (Note that the default Mac shell is zsh, not bash.) But most (with the possible exception of awk) offer a great deal of power even in their simplest forms. Most of these tools also make use of the power of Regular Expressions.
It is also worth noting that when KM spawns a shell it makes all of its variables, including local variables, available as shell variables. So, for example, if you have a KM variable called myVar
, you can access the contents of that variable from a spawned shell with $KMVAR_myVar
. Debugging is fairly straightforward because you can get code working in Terminal before importing it into KM.
For those unfamiliar with UNIX command-line text manipulation, here is a good primer:
Introduction to text manipulation on UNIX-based systems