MACRO: A Macro to Track Macro Usage

Perfect! It works beautifully now. Thank you, so much!

Is there a way to reset the counter for just one macro instead of reset all? I have this "track macro usage" in a macro with "The focused title changes". It now gives me hundreds of uses in the report. I should have put the “track macro usage” in the If-then action so that it only counts when the condition is true.

At the moment, there isn't—it's on the list of future features, as I wanted to wait until the database was in place to do any enhancements.

If you get the free app called DB Browser for SQLite, you can open the database, find the record, and just delete it—you then need to click the Write Changes button at the top of the interface.

At some point, hopefully you'll be able to zero or delete any record from the report window ... but not yet :).

-rob.

1 Like

Ah, ok ok. I will do the manual way until a new version comes. All good!

I notice a potential bug.
If I have a macro inside a macro, the count becomes 2x

For instance:

The first count is when running this "Open email" macro.
The second count is when running "Ultrawide Monitor - Left"

And if my "Ultrawide Monitor - Left" macro has the tracker, it counts 4x! (not sure why 4x, it should be 3x - scratch that - it should just be 2x, one for each macro.

Seems like the UUID is "inherited" in a sub-macro calls?

Ultrawide Monitor is just a simple Move and Resize Action.

I'm not seeing that here in my testing. After resetting the counters, I ran my MacroBackerUpper macro, where the main macro calls at least 10 other macros, and calls two macros (my task timer and my progress bar) at least 15 times each.

When it was done, it showed just one entry in the counter:

However, if the snippet above is part of a larger macro of yours, is it possible that routine gets called more than once? That's about the only reason I could see why it would double-count.

As a test, what's the count if you move the "track" command above the if-then? If it's right, that implies that the if-then is being called more than once. Debug mode would show you if that's true, and why it happens.

-rob.

Thanks for validating. Using debug mode, I can see that my macro only runs when the condition is met and the "track" command was issued once. I am dumbfounded why the report showed twice the count.

I wonder if the reset didn't take for some reason? That's about all I can think of it.

As I pondered after posting earlier, there's no way running sub macros should have any impact at all: The macro works by simply appending a value to a variable, and that's not going to happen unless that "Append Text" command is in the code the macro is executing. If it's in Macro1, then Macro1 gets counted.

But if there's no call to the counter in any of the sub macros, there's no way the counter can increment, as it's just a value in a variable written on command. So I too am stumped as to how you got those results.

Are they repeatable? If you zero the tracking and run that macro again, is it always miscounting? If so, can you send me the macro so I can take a look at it?

Edit: Do any of your sub macros call the main macro again?

-rob.

I reset and ran the macro again. It was counted twice.
Here are the macros:

This is the starting macro. It is in a Macro Group called Mails. The function of this macro: when I double click on an email in Mail.app, it opens in a new window and KM will move the window (2nd, sub macro) to the left of the monitor with a fixed height and size.

Open email with fixed window size (Mail).kmmacros (5.4 KB)

The 2nd, sub macro is in a Monitor Group.
Ultrawide Monitor - Left.kmmacros (3.9 KB)

Interestingly, Track Macro only shows one macro being run even though "Ultrawide Monitor - Left" was run:

(and pasting this window, I saw that your column name was named Macro Name, Macro Group when it should be the other way round :slight_smile: )

Oh my … such a fundamental mistake on my part, and all because I never do what you did: I never call the tracker from a sub-macro after calling it from the main macro. As soon as I tested your macros, I found the problem: I was using the wrong tokens in the tracking action.

I was using %Executing... tokens, which always refer to the originating macro. I should have been using %ExecutingThis... tokens, which refer specifically to the macro they are in, regardless of how they are launched.

So you were getting double counts because the Monitors macro counted like another Mails macro. Version 3.2 is out now, and fixes that problem (and also swaps groups and macros back where they should be in the report).

Thank you so much for using the macro in this way! I never even thought about what would happen if someone did that, and it shows :).

If there are other users of the macro out there, you should replace your tracking actions with the one in version 3.2. Your counts won't be wrong if you keep using the old one, unless you have tracker calls in sub-macros called by other macros that also call the tracker.

My sincere apologies, this was a real brain-dead mistake!

-rob.

1 Like

Yay! That's it! THANK YOU! :heart:

Hi rob, I hate to trouble you since you have been incredibly helpful but I think that double counting still exists.

It happened on the same macro I attached above but I thought I will try it on a simple macro. This very simple macro will just type a keystroke when I press Shift-Home. It highlight a word from the end to the beginning.

This GIF video will show you the double counting.
I started with a clean report.
When I pressed Shift-Home, the report showed a count of 1.
Then I pressed Shift-Home again and it showed count of 3.
I pressed one more time and it showed a count of 5.
Always an increment of 2.

This is using V3.2 with the %ExecutingThisMacro..

2023-12-07_14-21-07 (1)

Shift Home Key.kmmacros (2.3 KB)

I never consider reports of issues as "troubling me," other than I'm irked that I sent something out that didn't work, so don't worry about troubling me with such things!

And good catch — the SQL that did the totaling was double-counting under some situations. I believe that's now all sorted in version 3.3, which I just released. (This is complex SQL, beyond my skill level. I originally wrote about half of it, and ChatGPT wrote the other half. I went back through the whole thing with ChatGPT today, and it found a couple issues.)

-rob.

1 Like

I believe you have solved the mystery, rob! Great job! So far so good in my testing. Thank you again! I am happy that you created this macro!

Glad to hear it's working properly now, and thank you for the excellent bug reporting!

-rob.

1 Like

Version 3.4 out now, with a very minor change: The update checker only shows a notification if there's a new version available.

-rob.

2 Likes

I like how much care you put into this macro - especially when you have a macro to check for new version and checking its shasum to verify the validity :slight_smile:

2 Likes