Any suggestions on how to trigger a macro upon unlocking the screen?

I'm looking to activate the LastPass App upon unlocking the screen, so that I can authenticate to it. I did not see any triggers for screen lock/unlock. Running macos 10.14


You can use the Wake trigger if you are unlocking the screen from a sleep. But there is no "Unlock" trigger that I know of.

Here's a workaround.

It appears that this trigger will fire when you simply unlock the screen from a screen saver:


However, there is some overhead in that it will fire every time you change apps, but ignore all of them except when the KM Variable DND__ScreenLocked is set to "YES".

@peternlewis, is there a better trigger/method?

Here are my TEST Macros, that are NOT ready for production use. They are simply to give you an idea of what you might could do.

1. Run this macro to start the screen saver, lock the screen, and set the KM Variable

MACRO:   Start Screen Saver [TEST Example]

~~~ VER: 1.0    2019-01-17 ~~~


Start Screen Saver [TEST Example].kmmacros (2.5 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


2. This Macro should auto-trigger when you unlock the screen

MACRO:   App Activation on Screen Unlock [TEST Example]

~~~ VER: 1.0    2019-01-17 ~~~


App Activation on Screen Unlock [TEST Example].kmmacros (4.5 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.



1 Like

Thank you for the examples to try out. I actually use KM to lock my screen to keep the same key sequence as Windows. So I could test having that macro enable the "App Activation on Screen Unlock" macro so the overhead is only when I'm away from my Mac.

I just tested it out a so far it is working nicely. The lock macro sets the variable DND_ScreenLocked, and enables the activate macro. The activate macro brings up the LastPass Login via a hotkey and then as the last step disables it self. I will try it out for a while and see how it goes.

Thanks again for the suggestion.

1 Like

I have implemented another solution that does not require a custom macro to lock the device. Instead, my solution is:

  1. Trigger: At system wake
  2. Pause for 0.5 seconds /* Necessary because sometimes the display will flash an unlocked view when waking the device */
  3. Pause Until - The Screen - Contains - Image (with the image being a screenshot of the apple logo that appears in the top left of the menu bar)
  4. The rest of my macro

This requires you to have the menu bar set to NOT autohide. If you do have it auto-hidden, you could screenshot another item that is always immediately visible upon unlock.

Additionally, it requires the device to have been sleeping.