How to Make Hotkey Trigger Work Only at Specific Times?

I use a hot key to launch Slack. However, I only want to check it twice a day, between 8:30 and 9:00 a.m. and 3:00 and 3:30 p.m. If I attempt to invoke the hot key at any other time, nothing happens.

Intuitively, it seems like I would leave my hot key in place, and then use and IF action to test if the time is within one of those two time periods. If the condition is TRUE, the app opens as usual. If it’s FALSE, nothing happens.

The problem is that I can't figure out which condition to use to see if the current time falls within one of the two times slots.


Hey Michael,

Two approaches come to mind:

  1. Grab the hour and minute and use those in an IF-THEN action.

    • %Calculate%HOUR()%
    • %Calculate%MINUTE()%
    • Or bare functions of same.
  2. Use a time-triggered macro to enable/disable your Slack macro at the appropriate times.


Thanks, Chris. Here's what I came up with. There may be a more simple way to do this, but this works.

The big problem is the half hours -- it's easy to do "if hour is > 7 and < 10" to cover 8:00 through 9:59, but 8:30-9 gets more complicated. AM and PM confuses things further...

But the simple solution is to use a 24 hour clock, multiply your hours by 100 and add the minutes, so 8:30am becomes 830, 3:30pm becomes 1530, and so on. Note that this only works for time comparisons, not calculations!

So something like this (I've used TextEdit since I don't have Slack on this machine, change those actions and the hotkey to suit):

Launch Slack Between Certain Times.kmmacros (5.6 KB)


1 Like

Thanks, @Nige_S . That's very helpful.

Here's a re-write, using ternaries rather than nested "If" actions. It makes each condition a little harder to understand but it can seriously reduce the length of the macro and means you don't have burrow through nested "If"s to see the logic.

It also makes it really easy to add extra "OR" conditions -- you might want to ad another active time period, for example. In this case I've added an "override" hotkey trigger -- if you include the Shift key then the app will launch regardless of time of day.

Ternary Launch Slack Between Certain Times.kmmacros (4.6 KB)



@Nige_S, that is a fantastic re-write! It is much shorter, and I find it easier to understand. I also never thought about including an override and testing for a keystroke condition. Brilliant! Thanks so much.