I'm trying to find out whether there is any kind of equivalent command line one-liner which replicates the exact identical functionality of the 'Lock Screen' menu option available via the Keychain app in OS X 10.6
I'm aware of the all the 'usual' solutions (sleep/screensaver preferences to require a password on reactivation) but these are not suitable to me.
I'm also aware of this option:
/System/Library/CoreServices/Menu\ Extras/user.menu/Contents/Resources/CGSession -suspend
which is also not suitable for me.
The perfect functionality is the 'Lock Screen' option however I have not yet found an elegant way to call it.
At the moment, I am calling via Automator, which isn't elegant!
I have read much about this issue and my understanding is that no-one has yet found the 'holy grail' but I was wondering whether that might have changed.
Best Answer
In OS X 10.9 and later:
By itself, this command only causes the display to sleep, resulting in a black screen. By configuring your computer to require a password immediately after sleep, this one-liner works as a "lock computer" command. The preference is available at System Preferences > Security & Privacy > General.
Source: How to lock screen on MacBook Air?