Only run macro during business hours (Day function)

I'm running a macro using the Cron trigger and this string
0-59/5 9-16 * * 1-5
which suits my purposes perfectly, and runs the macro between 'business' hours - Monday - Friday.

However, I first tried to do this with a If All Condition Met Execute Actions action, using

I'm curious and couldn't work it out. Could I have added the day() calculation there as well to calculate day of the week?

I'd use a slightly different approach:

Keyboard Maestro 8.2.1 “Whistle While You Work” Macro

Whistle While You Work.kmmacros (3.1 KB)

That's a 9 to 6 business day. Adjust accordingly.

You can of course refine the time to include minutes. More info in the Wiki.

Thanks @mrpasini, but I can't see how you're getting weekday out of that? %ICUDateTime%H% gives you the current hour, I get that - I just don't see how you're getting Mon-Fri. Nice method regardless.

Here you go:

Whistle While You Work.kmmacros (3.6 KB)

But don't ask about holidays. I work weekends and holidays. :slight_smile:

1 Like

It's easy to get this confused (in fact, I did so myself while putting this test together) but it's not the DAY() function you want; rather, it's DOW() (short for "day of week", natch):

18 AM

(the reason it's returning false is because it's not yet 9AM in my time zone)

The method @mrpasini shows certainly works as well, but I personally would save the steps of making new variables and just use a text condition:

image

You may also be able to use a periodic trigger, depending on your needs:

27 AM

3 Likes

Aah yes, periodic trigger is probably what I was looking for at the beginning but was looking at time of day instead. That's a good few ways to do it and useful information all round.
The ICUdatetime token is very useful and versatile. And dow() as well.
Many thanks.

1 Like