What’s the best way to test if something happens between certain hours?
For example, let’s say I want to make a macro that checks to see if I am using Tweetbot between 7am and 11am.
I can do this with a shell script, like this:
#!/bin/zsh -f
# Purpose: check to see if the current time is between 7am and 11am (10:59 am, technically)
zmodload zsh/datetime
HOUR=`strftime "%H" "$EPOCHSECONDS"`
case "$HOUR" in
07|08|09|10)
echo yes
exit 0
;;
*)
echo no
exit 1
;;
esac
exit 0
but is there a way to do it in Keyboard Maestro without needing an external script?
The result is that if I launch Tweetbot, or if I switch to it (i.e. if it was running before 7am and then I cmd+tab to it), it will run the script and check the time. If the script is run between 07-10 a.m. it will return 'exit 0' and then Keyboard Maestro will quit Tweetbot (and launch OmniFocus, which is probably what I should be using anyway!)
I'm not sure if there's a better way to test the "IF" part of this. Does Keyboard Maestro have a way to tell if it is between 7:00 a.m. and 11:00 a.m.?
Simply you can use the “Calculation” condition. I don’t know how I can merge those conditions together, but anyway, this can work. HOUR() can get current hour. If current hour is 7, 8 , 9 or 10, this will return true. Hope it might help.