Hi, I have this situation:
I have a lot of the triggers coming from iTerm (the same trigger) that can also trigger a macro in Keyboard Maestro (KM)
From all of those triggers I would like to have a notification but not for every trigger and instead just a notification after all the triggers that come very close together (let's say there are 10 triggers with 1 trigger every ~0.3 seconds so I would like to have just 1 notification after around ~4 seconds so I'm sure a terminal finished all triggers)
I was thinking of solving this with a Pause action. The flow would be like this:
a trigger from iTerm starts running this script
osascript -e 'tell application "Keyboard Maestro Engine" to do script "ItermNotification"' that triggers a macro in KM
then KM sets a variable to 1 and then starts a Pause which will wait 1 second and when that wait finishes post a notification
another trigger of the same macro occurs after ~0.3 seconds
every one of these following iTerm triggers can only trigger the same macro in KM so this time the macro should do something different based on if the Pause is still running
- set again the wait variable to 1 second
- if a wait/pause is already happening, the variable should have changed already so the wait suddenly increases again to 1 second. And no other new wait is created.
- if no wait is happening already, start a new one with that variable
But I'm not sure how to handle this re-trigger logic Keyboard Maestro. Is there a way to check if a wait is already happening? Maybe is there a better way to solve this? I'm open to changes and recommendations
If I understand correctly, you want one of your flurry of triggers to trigger a KM macro, and you don't mind which one. If that's the case, you could do something like this:
This would be triggered by iTerm:
This is the submacro called by the macro above:
I can't actually test it as I don't know exactly what you're doing, but I've used a similar method before. Hopefully it might get you a bit closer at least...?
Hi! thanks for the quick response!
I've tried it and it mainly works! instead of receiving a lot of notifications I get a lot less. But I'm not exactly sure why I receive 2 or 3 notifications instead of 1.
Sorry for not giving before more context on what exactly I was doing. I thought it was not needed and it had to do not much with KM but in case it helps here it is:
I'm working with a Rails/React app and when I do a change in my React code that triggers a reload of page which triggers a lot of requests for Rails. This take some time from when I update my file and when I actually see a full page load in the browser.
I wanted to have a notification for when that full page load was finally over and thought maybe it can be linked to when the last request in Rails was completed. So that's the trigger from iTerm. When it detects a
Completed keyword it triggers the KM macro. But because there are a lot of requests that triggers the macro many times rapidly. And I would like to just care about the last of those triggers and wait ~1 second (decent time for the browser to handle the request response data and paint the screen) to say that the page fully loaded.
I hope this context helps some for testing (or even some other possible solutions). Thanks again!
Do you get all 2/3 notifications at once or do you get one and then the others 4 seconds later?
I would say at the same time (when the notification ends another appears right after that one). I also increased the wait time to 10 and 15 seconds (in case the notification stays for 4 seconds) just to test and it was still the same behavior of one notification after another.
Ok here's another idea.
Set this macro to be triggered by iTerm. In theory, it should only let one trigger through during while the macro is completing its run, hence the pause at the end. This makes the macro take a bit longer, by which time, hopefully all your triggers are done. The crucial thing with this way of using the Semaphore Lock is to set its timeout to something very short; in this case, 0.01s. Fingers crossed it does the trick.
zz Test 3.kmmacros (27.1 KB)