To lock the desktop or screen on Apple OS X, you can use the /System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession
command. This command allows you to lock the screen immediately, without requiring you to log out or enter sleep mode.
To lock the screen immediately, you can run the following command:
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
This will lock the screen immediately, and will require you to enter your password to unlock it.
Alternatively, you can also use the pmset
command with the displaysleepnow
option to lock the screen immediately. For example, you can run the following command to lock the screen:
pmset displaysleepnow
By using the /System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession
or pmset
command, you can easily lock the screen on your Apple OS X system. This can be useful for securing your system when you need to step away from it temporarily.