Is there any way to add some kind of timeout to a trigger after enabling the macro, so that, for example, I can enable a macro and then if I press the return key within 5 seconds it will run the macro, but after the time elapses it will not.
Here’s my case: I have a macro with a regular expression typed string trigger so that when I type a letter followed by a number and a space, it uses an AppleScript to look that code up in a database and save the information associated with that code in a variable. I would like it that if I press return within 5 seconds after having typed the code, it will type the information saved in the variable, and if 5 seconds elapse, it will assume I don’t want to type the information and do nothing.
Any ideas for how this could be accomplished?
Here's one way to do that.
Typed String with Confirmation.kmmacros (21 KB)
Macro screenshot
Note that the Pause Until... action has its timeout set as 5 sec under its gear icon. You'll have to adjust the macro to suit your needs, but the crucial things are to pause for the key condition and remove the typed string manually (if the pause condition was fulfilled and therefore didn't abort the macro).
I'm not sure why an extra ⌫ is required (one more than the number of characters in the trigger string), but it works.
1 Like
Because of the Return keystroke?
The extra delete needed raises a question -- does it matter what happens to that Return keystroke? If it can go to the active app without issues, @noisneil's method is quick and clean. If not then the keystroke must be captured -- which implies a second macro, with a hot key Return
trigger, that is enabled by the first and controls the first's branching.
Also, what should happen if you type, say:
a1 b2 <Return>
Should it look up both a1
and b2
, or only b2
?
1 Like
Thanks for the reply. That works pretty good, but it’s still a bit weird looking because it has to actually type the Return key and then delete it. I was hoping it would completely absorb the Return key. For example, what if I wanted to use Command Return instead of just Return. If I add the Command Modifier option to the Pause Until action, it beeps because the OS makes it beep and KM didn’t absorb the hotkey.
Using a trigger is better than Pause Until key press because Pause Until key press can easily miss a key if it is tapped quickly.
Basically, what you want to do is something like this:
- Set variable "Return Key Pressed" to 0
- Enable Macro "Detect Return Key"
- Pause Until variable "Return Key Pressed" is 1 timeout after 5 seconds without aborting.
- Disable Macro "Detect Return Key"
- If "Return Key Pressed" is 1
The macro "Detect Return Key" should set the "Return Key Pressed" variable to 1 and also disable itself.
1 Like
That is exactly what I needed.
It's amazing how there's almost always a solution to every single issue I have come across.
Thank you very much, Peter.
1 Like