Unlock Trigger / Wake Trigger

Hi,

I wanted to check the function of these - my system is set to require a password to unlock on wake, and on returning from the screensaver / display sleep.

I want to set something to run on wake, but to only run after the unlock password is used. So if the system wakes, but no password is entered (eg it wakes because of a power event, but then would go back to sleep without a password entry), KM won't run the macro. Importantly, I don't want the event to trigger after authenticating from the screensaver, or sleeping display.

Is that possible?

Thanks,

To clarify - if I add extra triggers with the green plus button, are they "and" operators, or "or" operators?

So if I set "At System Wake", then "When the Mac is Unlocked", will it only trigger if both those conditions are met.

I'm not sure if the "Triggered by any of the following" is referring to "any" as within that first section of triggers, or if it's (that first section), OR (Or by script), OR (Or by Execute Macro).

All of the above -- each trigger is independent and will fire up the macro. What you can do is test which trigger was responsible with "If... Then... Else..." or "Switch/Case" actions and act accordingly within the macro (see the various trigger tokens here).

Untested, but you could use a "Wake" trigger and then "Pause Until..." action that waits for a menu item to be available, like the Apple menu. Set the "Pause" action's timeout to something reasonable, like a minute, and to "Abort" if that time is exceeded.

Triggers are handled as “or” operators. In other words any single trigger will execute the macro.

I’m not at my computer right now but what about adding an action at the beginning or your macro to pause until the Return key is pressed. This way the macro wouldn’t execute until you hit that key, logically, after typing in your password. You could set its action timeout to something like 15 seconds to have the macro cancel if the system wakes but you don’t actually enter your password and hit Return.

@Nige_S beat me by one minute with that pause until action idea. :sweat_smile:

1 Like

Even better -- use the SCREENSAVER() function.

screensaverPause
...with a timeout to abort the macro. Note that it returns 1 when the screen is locked so you wait until it is not true.

3 Likes

Oh that's interesting - I had my simpler

  • At System wake:
    -- Pause for 15 minutes:
    -- (Action)

And it worked correctly. Do you know if the Screensaver variable also captures a locked screen after wake? The system doesn't wake to a screensaver, it's just a password field, with pre-login desktop picture.

https://wiki.keyboardmaestro.com/function/SCREENSAVER

It returns 1 if the screen saver is running, or the display is sleeping or locked.

1 Like

Oh that's great.

So with the action overall triggered by the Wake event, it's not going to fire off the final command when unlocking the screen, unless it's unlocking from sleep?

This being the final version of the time machine sudo stuff we were discussing, this should do what I want, correct?
image

On wake, it waits and does nothing until I authenticate, then it waits the time I specify, then it sends off the command to re-enable time machine. When it completes the shell script, it pops up a notification to that effect.

And if I fail to authenticate, would it remain active in such a way as to keep the system occupied and prevent it falling back asleep, given it's partway through a workflow? Or is that paused state a non-active one, like when the listener is waiting for trigger events to happen from scratch?

I don't know. But you avoid the issue by setting a timeout-and-abort on the "Pause Until..." action, which you do by clicking on the "cogwheel" Settings icon and:

The biggest problem will be that if the machine wakes and you don't authenticate then the macro will abort but the machine will remain awake -- if you then go to use the machine before it has gone back to sleep again the macro won't fire. If that's going to be an issue then you'll need to catch the timeout event and, rather than abort the macro, use an "If" action to either continue (authenticated) or "Put Computer to Sleep" (didn't authenticate).

Hey Folks,

Thanks for all the help on this - I have to take a few days away from it as some catastrophic system instability has reoccurred and I'm at the "walk away from the explosion in slow motion" stage of burning my operating system down and starting everything afresh... and finding out how much in Mojave doesn't work, that worked fine in High Sierra.

I'll pick this up when that's settled, but thanks once again for your help so far.