Hi,
I have a macro, and have added an action at the beginning and at the end of the macro to calculate the duration of the macro.
I run the macro more than once in a day, let's say 20 times depending on the day. And I would like a report that shows all the values the variable "Duration" has had. example:
1st time I ran the macro-> duration: 1 min
2nd time I ran the macro-> duration: 1.1 min
3rd time I ran the macro duration: 2 min
.....
20. duration: 5 min
So that I can run a report at the end of my day that tells me what was the value of the duration each time the macro was run. Is this possible?
Thanks in advance!
You can use the Keyboard Maestro Action Append Variable with Text
at the end of your Macro to build up a list of each time the Macro is run. By appending the text %Variable%Duration%
Or you can use the similar Action, Append Text to File
to do the same thing but saving the list to a text file somewhere on your computer.
For example, if you include the tokens to show the current date and time and have a line feed token you will get a list of the times date time at the front of each. Something like this:
%ICUDateTime%yyyy-MM-dd h:mm:ss% Duration: %Variable%Duration% min%LineFeed%
Which would give a list something like this (of course you can format the list however you want).
2023-08-02 09:28:35 Duration: 1.5 min
2023-08-02 10:28:49 Duration: 2 min
2023-08-02 11:29:04 Duration: 3 min
3 Likes
Adding an Append Variable with Text
action at the end of your macro should do this trick.
A bit more elaboratly done it could for you look something like this:
Variable log.kmmacros (5.0 KB)
Edit: Zabobon beat me to it
Edit2: I see now that my half-jokingly proposition to add the "1st", "2nd", "3rd time I ran the macro-> duration:" etc. falls through if you run your macro more than 20 times a day. "23th time" wouldnt sound too good …
Edit3: My compulsiveness (and interest in learning KM) made me create a version of this macro with corrected indexing also past 20. (Probably done in a very cumbersome way though.)
Write duration to log with corrected indexing.kmactions (6.2 KB)
1 Like
To save a log file to your desktop every day at 23:59 you could do something like this:
Variable Log file.kmmacros (2.5 KB)
1 Like
Thanks so much, this worked! Just one more thing, there's no way to select the format I want the file to be, right? For example excel rather than a text note. TYSM
Guys you're awesome! Thanks for all the tips!
Not sure if KM can create an Excel file directly, but if you add some commas or semicolons to the lines in the variable where you'd want a new column, like this:
%ICUDateTime%yyyy-MM-dd h:mm:ss%; Duration:; %Variable%Duration%; min%;%LineFeed%
(Here using Zabobons formating proposition as my indexing didn't work past 20)
You should be able to import it as .csv into Excel. With Numbers I can import a .txt file the same way, but if Excel needs for it to be fomated as .csv you can just swap out .txt with .csv in my earlier Variable Log file proposition.
But I don't know if importing it into Excel this way gives you what you need or not?
Append Variable with Text Comma separated.kmactions (541 Bytes)
Well, if you save as a text file with tab delimited values using the Keyboard Maestro token %Tab% to indicate where you want to split into cells, you should be able to open it with Excel or Numbers and it will be in the form of a table.
For example:

Opening in Numbers:

2 Likes
Just what I needed it!! TYSM , this works great for me!
2 Likes