Help With IF THEN as It Relates to Time

I have a macro that's currently working great, the only issue I'm having is how to set it so that it only runs during specific hours of the day

I suppose I would do this with the "if then else" action, but I guess i'm not clear on which condition to use to achieve this goal.

thanks!

Welcome @mikespax ! Are you wanting your macro to trigger automatically based on the time of the day or is it being triggered by something else and you only want it to continue if it's a specific time of day?

If you haven't seen these they're worth a moment of your time:

1 Like

I already have a series of actions running on an indefinite loop right now using the "execute until actions met"

I would like this loop to only run during a specific period of time everyday

Currently, I just manually start and stop the loop depending on what time it is

Sounds like the cron trigger might be a good fit for what you are doing. trigger:Cron [Keyboard Maestro Wiki]

1 Like

Thanks! I'll have a look

You can set up a calculation based on the time of day like so:

If Then Else Action (v10.2)

If Then Else.kmactions (1.6 KB)

Keyboard Maestro Export

1 Like

Ah that looks like it exactly! Thanks a lot!

1 Like

There are a bunch of ways to do this. But the first question would be why are they running on an "indefinite loop"? Is there no better way to trigger the macro(s) when required, rather than having them shouting "Are we there yet? Are we there yet? Are we there yet?" like a car-full of toddlers?

If you can find one/some triggers -- even if that's a periodic "run every minute" -- then you can use another, cron-triggered, macro that enabled your your macro just before you want it to start running and disabled it just after you want it to stop.

1 Like

That does sound more elegant, but hey it's working now – so I'll just halt my coding education here for now :smiley:

Screen Shot 2022-12-07 at 01.32.12

My ugly implementation...

It's more about resource management. Having one macro sat there all day every day asking every second "Should I, should I, should I...?" isn't so bad, but then you add a second and a third and a fourth...

Is there any event you could leverage to make your life easier? Start with "if I do this with a press of a button, what situation means I should press the button?". You've already got (it seems) "if the time is between 3pm and 4am" (but do remember that macros don't run if your Mac is off/asleep), but is there anything else? From the title it looks to be a copy-based macro -- could you use a watched folder trigger?

1 Like

I have it running 24/7 on a virtual machine doing this single task, so it'll do