I'd like to go to the Mac lock screen with a command line script. Many of the existing answers suggest something like osascript -e 'tell application "Finder" to sleep'
, but my computer does not allow me to change the settings to show the lock screen on sleep.
The AppleScript includes a command to open KeyboardCleaner which disables access to the keyboard and I'd like to run this while KeyboardCleaner is active. So any script/command that doesn't depend on keystrokes is required.
I'll run my AppleScript (which opens KeyboardCleaner and also locks the computer ) by running
python3 -c 'from file import *; script();'
This is what I've tried
osascript -e 'tell application "Finder" to sleep'
- my computer does not show the lock screen on sleep.alias afk="osascript -e 'tell application \"System Events\" to keystroke \"q\" using {command down,control down}'"
- this requires using the keyboard which is not possible for my use casepmset displaysleepnow
- same problem as 1tell application "System Events" to key code 12 using {control down, command down}
- same problem as 2
python3 -c 'from file import *; script();'