How to delay a macro only if it was executed automatically

Howdy all. I have a few macros that are set to run either periodically throughout the day or at a set time. I have a "wait for computer idle for 10 seconds command" that way they don't run while I'm in the middle of doing something.

However, from time to time I trigger these manually with a typed string. In those cases I, of course, want the macro to execute immediately. But because of the aforementioned 10 second computer idle command I still have to wait 10 seconds for them to run.

Is there a way to differentiate between the macro executing automatically (which should include the delay) and it executing with the typed string (which I don't want to include the delay), other than having two different macros that have different triggers?

Make the delay conditional (if-then-else) on the Trigger value itself.

I'm probably overlooking something really obvious but I don't see how to use a "If-then-else" command on a trigger...

Here's an example. After a minute of idle time, you should see a notification that stands in for your delay. If you hit the trigger, though, nothing will happen (no delay).

Optional Delay.kmmacros (2.7 KB)

1 Like

Got it working, thanks so much!


This is a good case to use the TriggerBase token which returns the “kind” of trigger, in this case “Hot Key Trigger” or “Periodic Trigger”, which is really what you are interested in.

An alternative is two or three macros:

  1. A sub-macro that does the work.
  2. A hot key triggered macro that just executes the sub-macro.
  3. A timed trigger macro that pauses until the Mac is idle and then executes the sub-macro.

Macro 1 & 2 could be combined in this case, but in the more general case where each trigger has different things to do it might be appropriate for them to be separate.

The If Then Else solution is probably the best in this case.


Ok I've been experimenting with that, and it works with the hot key trigger and also the typed string trigger. But I can't get it to work with the periodic trigger.

However, I typed in "Periodic Trigger" (minus quotation marks) in the If-then-else command but it doesn't work. Is that not the right token?

Also, is there a way to look up tokens? I searched the wiki help site but I couldn't find anything on it.

Periodic Trigger is correct if you're using a periodic trigger, but if you're using a macro based on the one @mrpasini came up with, the one you want is Idle Trigger. It appears that the type of trigger to use with the TriggerBase token corresponds exactly to the name of each trigger as shown when clicking the New Trigger button:


And yes, there is indeed a tokens section on the KM wiki:

1 Like

Got it! At first the periodic trigger wasn't working for some reason but I tried it with another test macro and it works fine. Maybe I had a typo or some other issue with my initial test macro.

I misworded my last question about tokens. What I meant was where can I find the value of a specific token (in this case the Trigger Base token. That makes total sense about the trigger values corresponding with the drop down list. I hadn't thought of that before. I had just read the wiki token page and from there gone to the Trigger Base page but it only listed "Typed String Trigger" as an example.

Thanks again!

1 Like

Thanks for sharing this info and this list.

@gglick and @peternlewis: I have updated the KM Wiki with this:
TriggerBase Token

1 Like