MACRO: A Macro to Track Macro Usage

Read outdated note

Update: Say hello to the fastest "version 2" update I've ever done. The Macro Usage Counter is back, and much better than it was before.

It's now a zero-overhead macro, as the only thing you have to add to each of your macros is a single action that appends that macro's info to a tracking variable. The work now only happens when you ask to see the usage report—it calls the processor to update the totals before the report is displayed. This is how it should have worked from the get-go, instead of trying to do everything in the background, which just made things miserable.

–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

I know Keyboard Maestro has some built-in usage tracking, and you can easily view your macros sorted by use order. But you can't see the actual counts in the sorted view; you have to use the inspector to see the count for a particular macro. It also tracks everything, all the time, and can't be reset (I don't think).

I wanted a tool that I would show all my macro usage in one report, that I could use to only track macros I wanted to track, and that would be easy to reset if I decided to do so (or, you know, had to do so during development because I did something stupid).

I decided to write my own simple tracker—mostly because I wanted the data to help thin my collection and see which macros I use the most, but also just to see what was possible. Here's the result—and this isn't really beta, as it seems to be working well, and there won't be any issues with updates (which is what caused me to pull this before):

macrousagecounter_22.zip (152.8 KB)

2.2 update: When usage counts exceed 1,000, they now get a comma in their displayed values. Also, and maybe more interesting, you can now live-sort any of the columns in the usage report.

2.1 update: A much-improved update routine (just run the update macro when you want to check), and a new framework that will verify in-macro updates, starting with the next update. Plus a reorganization of the macros in the macro group.

2.0 update: This is a total rewrite so that there's no background processing ever, and it works via a single "append to variable" action you insert in each macro. The work happens when you ask to see the report, which is (doh!) how I should have written it the first time.

1.1 update: I forgot to filter some variables that were used in regex searches to be regex safe. I warned you it was beta! If you installed the macro already, you can force an update check by deleting the global variable rg_MacroUsageCounter_lastchecked.

It's a very simple tracker—launch a macro, and the counter is incremented by one. But it does have some useful features…

  • Built-in backups, both by copying the permanent variable to another, and by writing a file in the /tmp directory, which macOS automatically cleans up (at a longer interval than I would require to notice that my usage data is missing). I also try to apply some logic and not write a blank variable to the backup file, for instance.
  • Restore from backup will compare the variable and file versions and let you pick which one you'd like to restore.
  • This includes my macro update notification macro, which I haven't yet posted here but will, so you'll get notified when new versions come out.
  • The report, as seen above, can be live filtered by typing in the box at the top. If you click on a row that you highlight with your mouse, you'll jump directly to that macro in the Keyboard Maestro editor.
  • There are a few simple tools that make it easier to add the "count this macro" action to your macros.

To use it, download the macro and install it, then activate the macro group. There's a "read me first" macro with some additional details, but to start using it, here's all you'd need to do:

  1. Open the macro named 01) •• Add this to your macros •• and copy the red-colored action—this is the "append to variable" action needed to track a macro.
  2. Paste the copied action at the top of each macro you'd like to track. (You could also put it at the end, if you wanted to only track macros that you had used through to completion.) There is a tool to make this easier, with instructions, in the TOOLS section. Read the how-to there.

Each macro that has the action added will now start collecting data. The data won't be processed until you ask to see the report, so there's no overhead at all. Once the report appears—it's assigned to open with a double-tap of the right-side Option key, which you can/should change—you'll see it with data that's been updated since the last time you ran the report.

I'd love feedback on this—it turned out nicer than I thought it would, and I'm finding it very useful. (Especially being able to jump right to edit mode from the report; that's a nice timesaver!) It should be safe to use, as it doesn't modify any existing macros, and only runs when you add its activating action to your own macros. You can disable the backup and update macros if you wish, as they're independent of the counter macro.

-rob.

9 Likes

Looks pretty cool! I don't have time to try it out right now, but I know what it's like to post a new macro and not get a lot of feedback, so... :slight_smile:

1 Like

Thanks Dan—though if I really wanted more feedback, not posting at 5pm west coast time would probably help too :).

-rob.

Actually, there are a lot of people overseas on this forum, so you'd be surprised. :slight_smile:

I've reposted the macro, and updated the text above to reflect the changes in this new version. It not only solves the update issues, but makes this a near-zero-overhead usage tracker—it only does the work when you ask to see the report.

-rob.

1 Like

This looks intriguing. I’ll take a look at it tomorrow. Thanks for sharing!

2.1 is out now, linked above. Improved update mechanism and a framework for verifying future updates.

-rob.

1 Like

2.2 is out, linked above, or check for updates from within 2.1. One new feature (the table columns are now sortable) and one enhancement (values over 1,000 are now comma-separated).

-rob.

@griffman I love all the work that you put into this awesome macro! However, I can't see to get it to run, even after reviewing all instructions provided. I've attached a screenshot of the error message that comes up when I attempt to run the report:

Any insight into what I'm doing wrong? Thanks in advance.

It's hard to tell specifically from that error message, but it clearly can't find something it's expecting to find. If you add a debug step to the main macro, you should be able to pinpoint the exact point where it fails as you step through it. That should be enough detail to figure out what's wrong.

-rob.

[SOLVED] Thanks for the debugging tip. Turns out it was failing due to the first action below the first comment ("Update the Counters Before Displaying Report").

Once I disabled that action, it ran like a charm. Thank you for putting this macro together!