So i want to know how to remotely unlock my mac via ssh so i don't have to put my password in front of people or having to make them look the other direction while i type my password. I have tried using the command on a post that is 7 months old but i get an error: "syntax error: Expected end of line but found class name. (-2741)". Any help will be appreciated, thank you in advance!
1 Answer
Set the time to require a password after sleep/screensaver in System Preferences > Security & Privacy > General to "immediately".
To lock the screen enter in the ssh session:
open -a ScreenSaverEngine
To stop the screensaver (=show the login screen) and unlock your user enter
osascript -e 'tell application "system events" to keystroke return'
osascript -e 'tell application "system events" to keystroke "password"'
osascript -e 'tell application "system events" to keystroke return'
Under certain circumstances you may have to enter the password one by one or first one keystroke and then the rest:
osascript -e 'tell application "system events" to keystroke "p"'
osascript -e 'tell application "system events" to keystroke "a"'
...
osascript -e 'tell application "system events" to keystroke return'
or
osascript -e 'tell application "system events" to keystroke "p"'
osascript -e 'tell application "system events" to keystroke "assword"'
osascript -e 'tell application "system events" to keystroke return'
-
1For some reason, at least on MacOS 10.14 this doesn't turn on the screen of a Macbook—though the system is unlocked alright, if one fiddles with the keyboard or the touchpad afterwards. But the solution is enough to jolt the machine into action, if one has some background apps that don't work so well in the locked mode (disk access seems to be limited). The ‘Unified Remote’ phone app can also unlock the screen via password input, but the screen is turned on too—idk what's different between it and AppleScript.– aaaCommented Jun 25, 2023 at 9:22