Skip to content

Instantly share code, notes, and snippets.

@hiilppp
Created April 16, 2014 19:20
Show Gist options
  • Save hiilppp/10922837 to your computer and use it in GitHub Desktop.
Save hiilppp/10922837 to your computer and use it in GitHub Desktop.
AppleScript to unlock your Mac's screen. (Use EventScripts to automatically trigger script when a Bluetooth device (e.g., your iPhone) enters your Mac's range: http://www.mousedown.net/mouseware/EventScripts.html)
-- You need to create a Keychain item whose name matches what you use in place
-- of "[keychain_item_name]" on line #7 (and whose password is identical to your
-- user account's password).
tell application "System Events"
if ((get name of every process) contains "ScreenSaverEngine") then
set pw to (do shell script "security find-generic-password -l \"[keychain_item_name]\" -w")
tell application "ScreenSaverEngine" to quit
delay 0.5
keystroke pw
keystroke return
-- set require password to wake of security preferences to false
end if
end tell
@hiilppp
Copy link
Author

hiilppp commented Apr 16, 2014

@dionmunk
Copy link

dionmunk commented Dec 3, 2014

I've attempted to use this in Yosemite to no avail. You don't have an updated version of this do you?

EDIT: Never mind! This actually works perfectly. Thank you for the awesome script.

@sunnyagarwal
Copy link

If i am using apple script for this script it is not working. Any suggestions.

@jqgsninimo
Copy link

jqgsninimo commented Oct 19, 2016

Tested this on macOS Sierra(10.12).

do shell script "caffeinate -u -t 2"
delay 1
tell application "System Events"
    keystroke "<password>"
    delay 1
    keystroke return
end tell

Reference:

@sfreek76
Copy link

sfreek76 commented Aug 9, 2022

Hello

I know, it's a pretty old post but it's my best chance at the moment. I would like to unlock mac OS Montereys lock screen with the following script I've modified:

tell application "System Events"
		click at {100, 200}
		delay 1
		keystroke "mypassword"
		delay 1
		keystroke return
end tell

It works so far but it won't fill my password in, it only strokes the return key. Unfortunately I'm no programmer so I would appreciate any help on this... Many thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment