Perform One Task in the Macro Only if It Has Not Been Performed in the Last 5 Minutes

I want to perform one particular step of the macro (resize window) only if it has not been performed in the last 5 minutes, and ignore this step otherwise. How can it be done?

I think I found the solution - let me know if there is a more elegant way to do it:

Well, I spoke too soon - it does not work. What am I doing wrong?

That'll work as long as your macro is running. So if it is on a long-running loop you'll be fine -- but if you run it now and then again in 10 minutes your Local variables will have reset in the new instance and Local_TimeExuted will be empty. AFAIK your test will always evaluate as false and the window will never be moved.

To use a variable across macro instances, use a Global. I define them explicitly with a Global_ prefix, but you can just miss out the Local_ bit. So use Global_TimeExuted or just TimeExuted.

As @Nige_S mentions – local variables are destroyed as soon as your macro stops running.

Read up on local variables and variables in general:

manual:Variables [Keyboard Maestro Wiki]

Scope of variables is part of programming 101 and should be sufficiently understood.

Thanks @ccstone and @Nige_S !

1 Like

Another approach would be to use a semaphore

Begin your macro by testing the semaphore to see if it's locked. If it is abort, otherwise lock it now.

Do your window move.

Wait 5 minutes and unlock the semaphore.

Ah..I see that you mentioned it's just a single action in a larger macro. Still doable, just move the pause and semaphore unlock to another macro that you invoke asynchronously.