Execute actions by odd and even numbers

I found a macro on the forum, but it doesn't seem to work.

I want to do this. It is when I run the macro the first time to execute an action, and the second time to execute another action.

Then the third time it runs the first action again, and the fourth time It runs the second action. Repeat like this.

I don't actually need to count how many times the macro was run, I just need to know if the number of macro executions is even or odd.

So I'm trying to determine this based on the macro I found, but it won't run. Is there any other way to do it?

Sequential Number of Variables.kmmacros (3.3 KB)

Since you don't want to actually count the number of executions, simply set a global variable (globals persist across macro executions) and flip it on each run -- if you use 0 and 1 you can use the value directly in your if condition:

Alternating Branches.kmmacros (2.9 KB)

(You test for if 0 then do even, else do odd because the first time the macro runs the global will be undefined and the test will fail. And I've put an explicit "flip" action in each branch so you can easily see what's happening.)

Doing it like this has the added advantage that you can choose whether or not to flip the variable if your macro fails to execute for any reason. And if you ever want to start from "zero executions" again, delete Global_alternating in KM's Preferences->Variables pane.


Thank you very much.
Good details.
This is I want.