Macro doesn't work when Mac is locked

I have a macro which works a wonder when I am trying it manually, but doesn't when the Mac is locked.

The macro opens a web page, take a screenshot, paste it into a new mail and send it along.

When the screen is locked, on unlocking I found just the empty mail, the clipboard full with the requested image... It gets stuck at pasting, but when doing it manually it works.

What could be?

Thank you, love KM.

Link to an export of the macro:

You can share the macro directly to the forum using the Share button at the top of Keyboard Maestro.

In any event, you pretty much cannot do any UI when the Mac is screen sleeping, screen saving or screen locked. So presumably you cannot do the paste because the Paste requires the ⌘V key to be simulated, which you cannot do on a locked Mac.

My Mac locks the screen, as I have an AppleWatch it can unlock it if I am close by. So I have a wakemeup macro that does that. It's a bit overkill in mine, it tries pressing return, wake screen and stop screensaver, and it does those about 5 times if required (if the screensaver is now inactive then it skips them), it also sends notifications so I can see how long it took, usually it gets it by the second attempt.

All the folded red blocks are the same, other than the notification (0,1..4)

Might help, if not then ignore.


Understood, both of the things, thank you.

What would be a way to make a macro that gets the same result, if any?

The macro open a web page with my wordpress blog's pending posts, take a screenshot and send it via mail, so that I always know how many pending post there are and I do not run out of them.

I would like it to run overnight, every night, when the Mac is left unattended.

Thank you.

Keep the Mac awake, keep the Mac unlocked (physically lock it in a secure environment), and Wake Screen at the start of the macro.

Thank you. What about finding a way to get the same result without locking the mac, which is not feasible? Can you use curl o such? Thank you.

Wordpress will have an API that you can investigate. If all you want is a number of pending posts, the API can just give you the number. But if you’re not familiar with using remote APIs, it’s probably too involved to go into. It’s just something that occurred to me when you asked about using cURL.

If you’re using Apple’s, you can use AppleScript to create an outgoing message with a file attachment and send it. So rather than (or as well as) sending the screenshot to the clipboard, you can save it as a temporary file in order to email to yourself.

Alternatively, I notice you use Dropbox, so you could save the screenshot file to your Dropbox folder (assuming you have Dropbox installed on your Mac), then access it wherever you are.


I believe that I've got this issue resolved. In tinkering with an AppleScript (the basis of which I found on StackExchange) I found that when placed at the beginning of the macro it will successfully unlock the screen.

Note that you should run the macro manually a couple of times before relying on the script because you may have to give permission to a couple of services in the Security & Privacy Preferences pane to allow the script to control it. Replace the "YourPasswordHere" with the password that unlocks your screen/Mac:


This will unlock the Mac and allow you to proceed with the remainder of the automation as programmed into KM.

I'm glad you resolved your issue, but I hope you know that programming your Mac password in clear plain text is a HUGE security risk.

Thanks but it’s buried in an AppleScript and isn’t transmitted anywhere, nor shared on Dropbox or anything like that. It’s only invoked automatically on a computer in a secure room and the screen locks again very shortly after the macro runs (or I could add a “lock screen” step).

Hi @Scott72, I unlock my Mac's with this Siri shortcut

You could use/modify the KM macro for your purposes. It works very reliably

To be clear, I want to state that I appreciate your sensitivity to security. I am generally hyper-sensitive to it, too. I'm in the cybersecurity industry (a few patents in the 2FA area) and watch these things very closely.

First of all the computer's in my house, not an office. If someone unauthorized gets into my house and breaches the password of the desktop Mac in my office I've got way bigger problems than that password.

Also, the computer is locked when I'm away from the desk so someone would have to know the password in order to get to the AppleScript to see the password. The folders in which I store my scripts aren't on a network drive, Dropbox, shared folders or anywhere other than the local drive. The drive itself is encrypted using FileVault 2.

So, while you are correct that there is a risk involved, it's one that I'm willing to take in this situation. That all said, I agree keeping or sending passwords in plain text is a risk. Unless it is very carefully thought out I don't recommend that anyone do it.

Thank you.

Thank you for your kind response. I think you may have misinterpreted my requirements, though, because what I needed was a mechanism to unlock the Mac, not lock it. Nonetheless I have resolved this with a simple AppleScript and did not have to invoke a Siri shortcut to get this done.

With my KM macro in the above post I unlock my Mac :thinking:
I also use the KM macro with a BetterTouch Tool gesture to unlock my Mac, as well as apps (with small changes).
So a Siri shortcut is not a prerequisite for this. It was just about the KM Macro as an alternative to your AppleScript.

I use Power Manager to wake the Mac when "time of day" macros need to run. I set the mac to wake about a minute before the Keyboard Maestro is supposed to run.

1 Like

I can only confirm the advantages of Power Manager @bocciaman :+1:
I have created a simple workflow with a KM macro and a pushover notification that sends various battery status displays to my iOS devices.

This works fine even when the MacBook Pro is closed: