A few weeks ago I created a macro that keeps track of the last time you ran it, and will not run again if it ran in the last X seconds/minutes/hours.
Now I've achieved the same thing, but there's no macro required. It's all handled by inline statements. Here's how it looks when you use it:
The above code will play the "Tink" sound, but only once every 5 seconds at maximum, no matter how many times you run it? How? Let's open up the "Try" action a little, and we see this:
As you can see above, there are two green actions. One contains the number of seconds minimum times between, in this case, "Play Tink" actions. The other one contains assigns a unique name to the local variable "LocalZ" which I recommend starts with the letters "Timer" followed by any sequence of digits, but they should be unique. So I just press a bunch of random digits.
That's all there is to it. You just copy this action block anywhere in your app, and change the two green actions.
The real magic happens in the block called "Common Elements." You never need to open that block, but here's what it contains:
That code handles the logic of "don't let the code run if it has already run in the last N seconds." I won't explain it because there isn't any benefit to explaining it.
This code could be slightly simpler if there was a token that could return the UUID of the current action. I'm not sure if KM uses UUIDs to identify individual actions, so this may not be possible. But if it was possible, it would look like this:
I will upload the code in a few seconds after this paragraph...
Template Action for N second limited actions
Try-Catch.kmactions (5.3 KB)