Mac OSX: Wake up from sleep and login last user via ssh + caffeine

PHOTO EMBED

Sun Aug 28 2022 22:59:22 GMT+0000 (Coordinated Universal Time)

Saved by @marcopinero #bash

caffeinate -u -t 2
osascript -e 'tell application "System Events" to keystroke "mypassword"'
osascript -e 'tell application "System Events" to keystroke return'
content_copyCOPY

For Mac OS X. Connecting via ssh and sending these commands will wake up your machine and login using password and last logged user. I needed in a project using Mac OS X as Monitor for special application controlled remotely. For going back to sleep: $> pmset displaysleepnow