Please Help Me! I'm having trouble making a macro timer

I'm sure it's something trivial. It works on the first pass but the second pass gives a duration of 0

Z Tester Macro (v10.1.1)

Z Tester.kmmacros (3.3 KB)

NOW() gives current Unix time, which only resolves down to seconds -- with a 0.7 second pause there's ~30% chance you'll get the same result in both variables.

Edit to add:
Since you're concerned with the time difference @_jims's answer below is a much better solution. Mine might come in useful to someone, sometime -- though I can't think how! --and, if nothing else, is evidence how much I've still to learn!
End edit

If you want finer resolution you'll have to use an "Execute script" step -- for example, this action uses perl to generate timestamps to 1/10th of a second:

perlTime.kmactions (869 Bytes)


EDIT 2022-06-06 21:4511 EDT:

Hi, @larsof54. The Keyboard Maestro native SECONDS() and MILLISECONDS() functions will give you millisecond microsecond resolution, but the Display Text values can be formatted as required using the CalculateFormat Token:

DOWNLOAD Macro File:
Timing a Macro (seconds | milliseconds).kmmacros (16 KB)
Note: This macro was uploaded in a DISABLED state. It must be ENABLED before it can be run. If it does not trigger, the macro group might also need to be ENABLED.


1 Like

...and because we're only concerned with a time difference, this is much better than my suggestion. Nice, @_jims -- very nice!

Back to re-read the manual, hanging head shamefully...

1 Like

Haha @Nige_S; I learn (and re-learn) techniques every time I visit this forum.

Upon more careful reading of the MILLISECONDS() wiki entry I see it states fractional milliseconds. I wonder if that's a typo since it seems unlikely that a macOS API would return uptime at a higher resolution than milliseconds. @peternlewis, is my assumption correct?

MILLISECONDS() is basically MICROSECONDS()/1000. So it returns fractional milliseconds.

1 Like

Okay, thanks @peternlewis. I've corrected my above entry.