Macro Reporter Macro

Macro Reporter Macro

Latest Version: Macro Reporter 3.0d 6 December 2023
Macro Reporter 3.0d.kmmacros (12.5 KB)

I've gotten so used to looking up my text expansions and their triggers in Brevis that I wanted something like that for my non-text expansion macros. And here it is.

There are a few macros posted here that do something like this and I borrowed heavily from them. The AppleScript to make lists of active and inactive Macro Groups is derived from @ccstone while the JavaScript that mines the group for macros, times used and triggers is predominantly from @ComplexPoint with a dash of JMichaelTX (for the triggers). The bugs are all mine, though.

It does the job but I wish I had been able to figure out:

  • How to fold the JavaScript into the Custom HTML Prompt so you wouldn't need a Stats button. You'd just pick another Group from the popup and the report would change instantly, no redrawing the HTML window. I tried, but I got an "Can't find variable: Application" error in the JXA. [Solved in v3 below in this thread.]

Anyway, as it is, Macro Reporter shows all you Active Groups followed by Inactive Groups in a popup. After you select one and click the Stats button, the scrollable report window fills with a table that shows the Group and whether or not it is enabled followed by its individual macros with their times used, enabled status checkbox, name and trigger.

It does skip macros whose names include a string I use to delineate sections of macros in palettes. Those include consecutive hyphens, rules and spaces between each letter. If that's a conflict on your setup, search for "regex" in the JavaScript and edit it.

If the Group forms a palette, the table ends with the total times the total times the palette has been used. I think.

That's it. Sweet and simple.

Macro Reporter.kmmacros (16 KB)

UPDATE: I eliminated the Stats button in this version with a simple on change observer in the HTML. And I added a Wait window while the macro is gathering information. But look down a few posts for v2.0 of the macro, which eliminates the HTML window redraw as well, making a much smoother and faster experience.

Macro Reporter.11c.kmmacros (18.7 KB)

UPDATE: Version 3 of Macro Reporter, which can execute macros and gives a time-saved report, is available below.

UPDATE: Version 3.0d of Macro Reporter cleans up the palette report at the bottom of the display.

8 Likes

Testing version 2.0a right now. It eliminates the Stats button and the HTML redraw, reporting instantly on subsequent groups.

It uses a large local variable (192K on my system) in a JSON format to store the Keyboard Maestro macro information but that doesn't seem to bother Keyboard Maestro. I thought it might until I read a recent post by Peter Lewis.

So, coming soon...

Macro Reporter 2.2

This version of Macro Reporter improves on the initial release four ways:

  • It pops up a Please Wait window when invoked while it collect data.

  • It eliminates the Stats button, displaying a group's macros immediately when a new group is selected from the popup list.

  • It does not redraw the HTML window to report a new selection's macros.

  • Faster startup after eliminating AppleScript and Perl actions.

To do that, I broke up the original JavaScript action into two parts. The first part runs before the HTML window is displayed to create a JSON-formatted local variable of all macros and format the group names as an HTML Select.

ss-255

The local variable of macros is 192K on my system.That's a large variable but Peter Lewis has said, "Keyboard Maestro itself can have arbitrarily large variables." An issue would arise if the macro were reading that variable as an environment variable in a script (where it would be excluded), but it's not.

The second part is tucked into the HTML Custom Prompt to read the local variable of macros to find the group you selected and format the macro information in it for display.

USAGE

Macro Reporter lists your Active Groups followed by Inactive Groups in a popup. After you select one group, the scrollable report window fills with a table that shows the Group and whether or not it is enabled followed by its individual macros with their times used, enabled status checkbox, name and triggers.

It does skip macros whose names include strings I use as titles to delineate sections of macros in palettes. Those include consecutive hyphens, rules and spaces between each letter. If that's a conflict on your setup, search for "regex" in the JavaScript in the HTML Custom Prompt and edit it.

If the Group forms a palette, the table ends with the total the palette itself has been used.

If you run the same Keyboard Maestro macros on multiple systems, the reports will vary from one system to another, showing the macro usage on each particular system.

That's it. Sweet and simple.

Macro Reporter 2.2a .kmmacros (12 KB)

2 Likes

@mrpasini, very nice! This will be a great tool to use when I want to delete old, unused macros. Thanks for sharing!

Thanks! Getting the usage information is surprisingly helpul. And it helps me remember the triggers, too. :grin:

Version 2.1a eliminates the AppleScript that collects the group names, which can be done in the first JavaScript action when the JSON-formatted macro list is created.

I may also consolidate the Perl code that builds the HTML Select into that JavaScript action to save another second and make the macro even smaller. So stay tuned.

Version 2.2a eliminates the Perl action that builds the HTML Select for the popup of group names. That code was folded into the JavaScript. So instead of three actions (AppleScript, Perl and JavaScript) to get to the HTML prompt, the macro now uses just one. That cuts the size down to 12KB and makes startup as fast as it's going to get.

Macro Reporter 3

This version of Macro Reporter improves on the initial release six ways:

  • It pops up a Please Wait window when invoked while it collect data.

  • It eliminates the Stats button, displaying a group's macros immediately when a new group is selected from the popup list.

  • It does not redraw the HTML window to report a new selection's macros.

  • It adds an estimated Time Saved report for each macro, expressed as hours:minutes.

  • Macro names can be clicked to execute if the context makes sense.

  • Headings for the Hot Keys and Time Saved columns have been added.

To do that, I broke up the original JavaScript action into two parts. The first part runs before the HTML window is displayed to create a JSON-formatted local variable of all macros. That's 192K on my system.

ss-256

That's a large variable but Peter Lewis has said, "Keyboard Maestro itself can have arbitrarily large variables." (See Why am I getting KM Engine Logs about Local Variables? - #3 by JMichaelTX) An issue would arise if the macro were reading that variable as an environment variable in a script (where it would be excluded), but it's not.

The second part is tucked into the HTML Custom Prompt to read the local variable of macros to find the group you selected and format the macro information in it for display.

USAGE

Macro Reporter lists your Active Groups followed by Inactive Groups in a popup. After you select one group, the scrollable report window fills with a table that shows the Group and whether or not it is enabled followed by its individual macros with their times used, enabled status checkbox, name and triggers.

It does skip macros whose names include strings I use as titles to delineate sections of macros in palettes. Those include consecutive hyphens, rules and spaces between each letter. If that's a conflict on your setup, search for "regex" in the JavaScript in the HTML Custom Prompt and edit it.

If the Group forms a palette, the table ends with the total the palette itself has been used.

Time Saved estimates are from Keyboard Maestro's data and are only rough approximates, more important as relative comparisons than absolute data.

Hovering over a macro name will turn it from white to yellow, indicating a click will execute it. But the group's activation settings matter as does what application is activated. Macro Reporter doesn't check any of that.

If you run the same Keyboard Maestro macros on multiple systems, the reports will vary from one system to another, showing the macro usage on each particular system.

That's it. Sweet and simple.

Macro Reporter 3.0a.kmmacros (12 KB)

UPDATE: This minor update to Version 3.0b adds a macro count to the status line of any palette report.

ss-353

The count may be higher than the number of displayed macros in the report if the palette includes titles or spacers. Hovering over the count will remind you with a text hint that this is the case.

Macro Reporter 3.0b.kmmacros (12.3 KB)

4 Likes

Thank you for this useful macro @mrpasini!
I'll also snatch the progress bar/close actions for other macros. :smiling_imp:

That works nicely for times when you can't calculate how far along in some invisible process you are. As an alternative, I tried just speaking the phrase but that seemed to make a larger macro.

If you can calculate your progress, though, Keyboard Maestro 10 has a lot of new options to play with.

Just saw this in one of the first posts in the thread.

It sounds as if you are trying to find the Javascript for Automation library in the browser JSContext. It's only available in the completely separate JXA JSContext.

Two quite different instances of JavaScript interpreters there.

There is, of course an interface for exchanging values between the two:

window.KeyboardMaestro.GetVariable( 'KMVariableName' )
window.KeyboardMaestro.SetVariable( 'KMVariableName', 'value' )
1 Like

Yes, in another thread in which I found your code for listing a group's macros (but which escapes me), we discussed this (several weeks ago). And I temporarily abandoned the improvement because of the size of the local variable (based on the plist size).

Then I read something Peter wrote that Keyboard Maestro can handle large locals, so I went back to it and used the one interpreter at the beginning of the macro to create a JSON list of the plist (as a list of both active and inactive groups) that I could pass to the other interpreter in the Custom HTML Prompt. As you originally suggested before I became discouraged by the size of the local variable.

And it (v3) works well, quickly compiling the HTML display of macros for any group selected without redrawing the HTML window (which is what I was after to begin with).

I should probably edit the original post to remove all that, but I thought it instructive to see the development of the project.

That should bring you up to date.

2 Likes

The minor update Version 3.0b above adds a macro count to the status line of any palette report.

2 Likes

Macro Reporter 3.0d (above) clarifies and beautifies the palette report at the bottom of the list to eliminate the misleading count. If you have titles or spacers in your palette, it counts those macros (as the mouseover explains).