beta.blog

macOS: lock screen right from Terminal

by on Nov.14, 2018, under MAC OS X

There are multiple ways of locking ones screen from Terminal.

A common way of doing so is by using CGSession which will trigger a fancy animation and bring the user to the “locked screen” window where they’ve to enter the account password in order to proceed. Simply open up a terminal prompt and enter the following command:

/System/Library/CoreServices/Menu\ Extras/user.menu/Contents/Resources/CGSession -suspend

Unfortunately this solution might cause some rendering bugs in Firefox on macOS Mojave (10.14).

From macOS 10.9 on one might as well use pmset in order to get the same result:

pmset displaysleepnow

This command will lock the screen and also turn off the monitor. User input (i.e. keyboard/mouse) is required prior to continuing.

:

Leave a Reply

*

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!