Is there a way to unlock screen programmatically? [duplicate]

The duplicate link I added has some really good Apple Script options.

$ osascript -e 'tell application "System Events"
> keystroke "verysecurepassword"
> key code 36
> end tell'

I might also suggest using LockScreen. It's a hidden application that comes preinstalled and is protected by System Integrity protection. It will put a lock icon on the screen, lock the keyboard and mouse, and freeze the Touch Bar (Sounds malicious, right?).

  1. System Preferences > Security & Privacy > Uncheck "Require Password...."

  2. To lock the Mac use

$ /System/Library/CoreServices/RemoteManagement/AppleVNCServer.bundle/Contents/Support/LockScreen.app/Contents/MacOS/LockScreen
  1. To unlock the Mac use (non tested but should work)
    $ killall LockScreen