How to Run a Macro Weekly and when the Mac is Unlocked

Hi - I would like to run a Macro every Sunday when the Mac is unlocked. This requires chaining the "Time of Day" and "Unlock" triggers.

Is this possible given the default is "Triggered by Any of the following"?

Keyboard Maestro 12-22-2022 at 01.31.59 PM

No -- an "and" would mean "Run this macro when I unlock the Mac at this particular time". A trigger is an event (unlocking the Mac), not a state (the Mac is unlocked).

What you probably want is the timed trigger and then the first action of your macro to be a test -- "if screen is locked then cancel the macro". You can use the SCREENSAVER() function, which returns 1 if the screen is locked, asleep, or the screen saver is running.

1 Like

Hey Adrian,

@Nige_S is right. You can't chain the triggers.

To answer your question more specifically we need for you to be more specific about your requirements.

Thinking out loud here...

I'm guessing what you want is to run your macro on Sunday @ 08:30 (or after) when your Mac is unlocked.

If so then you'll need a macro with an Unlock Trigger:

  • Activate on Unlocking the Mac
  • Poll the day and time
    • If in the right ballpark
      • IF macro has not run already
        • Run the body of the macro

Maybe store the last day the macro was run in a global variable to prevent it from running more than once:

Day of the month:

DAY()

Here's the day of the week calculation:

DOW(NOW()) = 7

Hour:

HOUR(NOW()) >= 8

Minute:

MINUTE(NOW()) >= 30

Oh, well – here's a full scale example:

Unlocked on Sunday @ 08-30 v1.00.kmmacros (13 KB)

Display-Macro-Image

Keyboard Maestro Export

-Chris

3 Likes