Is there a way to unlock and lock screen from command line, via ssh? I know /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
command, but it doesn't seem to work via ssh. The perfect solution would be a command, that I could type logged via ssh and it would unlock the screen or lock it back again, so I don't need to tell anybody my password, if he wants to use it. Is there any builtin tool, that would provide such functionality?
Unlocking and locking mac screen via ssh
remote controlremote desktopssh
Related Question
- Is it possible to terminal login remotely (outside local network) to the mac at home via SSH + VPN
- Mac – Connecting to Mac Mini via SSH unreliable
- MacOS – Enable screensharing via SSH and setting password
- How to Tunnel SSH via SSH with FoxyProxy
- How to use the `security` command-line tool to add a keychain
- Reset Mac user password via SSH
Best Answer
There are many ways to lock and unlock your Mac via SSH. The easiest and probably the fastest way is to use
osascript
(applescript).Locking Mac
To do this, log in via ssh and type in
You can switch Finder for System Events, but that means more characters to type.
Unlocking Mac
To wake your Mac is a little harder.
There are two ways to do this.
You can use
osascript
again.This tells it to keystroke the left arrow key which should wake your Mac up from sleep.
You can also use the
pmset
command.Use a date and time that has already passed.
Of course you will need to keystroke your password via Applescript, e.g.
An alternative to this could be the Remote Wake Up app for Mac, but I am not sure if you can put a password in.