Simplest possible timer macro with restart

Hello,

I want a simple timer that will restart every time a macro is re-triggered, and not having the same macro start in a separate instance.

Something like:

  • Set VARIABLE to True
  • Pause 5 minutes
  • Set VARIABLE to False

If the macro is triggered before the Pause has reached 5 minutes, it should abort and restart the Pause, not trigger multiple Pauses in different instances.

There are multiple "Cancel" options, but no "Cancel all other instances of this macro" or similar.

Any ideas?

You can use the Semaphore_Lock.

My explanation: Help: Semaphore - #6 by JuanWayri

If you need specific steps for your macro, just ask =)

Why?

I'm wondering if a better way would be to set a global variable to "now + 5 minutes" every time the macro runs -- then instead of checking for true or false you can check NOW() against the global.

You can "cancel all other instances of this macro" -- but you'll need to get the list of %ExecutingInstances% and work through them, cancelling any instance UUID whose %ExecutingInstanceName% matches %ExecutingThisMacro% but which doesn't match %ExecutingInstance%.

Which is a lot more work :wink:

1 Like

That seems like a better idea, yes, thanks for that.

The use case is that I record key switches for MIDI recording to switch between different sounds. Every time I record, I want KM to send the last keyswitch that I pressed (since my software lacks that feature and resets the sound on stop).

All that works, but I find it annoying that it always sends it, even though I've moved on to do other stuff. So if I haven't triggered a key switch from 5 minutes, I'd like it to not send it.

The idea with the timer was basically that every time a keyswitch is sent, the timer resets to 0. Checking towards NOW also seems like a better solutions as it prevents an instance open in the background. Thanks for the tip!