"Creating a Sequential Number Generator in Keyboard Maestro for Macro Triggers"

I am looking for a function in Keyboard Maestro that, upon triggering a macro, provides me with a number ranging from 1 to 5.

The first time I trigger the macro, it should give me 1 and store this number in a variable called "Counter."

The second time I trigger the macro, it should give me 2 and store this number in the "Counter" variable.

For each subsequent trigger of the macro (3rd, 4th, and so on), it should give me the corresponding number (3, 4, and so on) and update the "Counter" variable accordingly.

This sequence should continue until the 5th trigger of the macro, where it will give me 5 and update the "Counter" variable accordingly.

After reaching 5, the sequence should reset, and triggering the macro again should give me 1.

Easily done with the Set Variable to Calculation action, set Counter to Counter+ 1, and then a test for an invalid or out of range counter and reset it to 1.

Note that either you need to ensure Counter has a numeric value to start with, or you need to disable the Failure & Notification of errors on the first action (in the gear menu for the action). Otherwise, with Counter having no value the first action will fail and abort the macro.

image

1 Like