Create lock screen alias in Mac terminal

You can use a terminal command to lock the screen in Mac.

To do that you need to add the following like to your bash_profile (otherwise every time you restart, you'll lose the changes).

A) I don't have bash_profile

Create the file:

sudo echo > ~/.bash_profile

B) I have bash_profile

Edit the file (the name might vary depending on that you set the moment you created it):

sudo nano ~/.bash_profile

Add the following line (you can change the "lock" keyword to something else):

alias lock='/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend'

Save the file.

About Rick

Senior Front-end Software Engineer from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

Leave a Reply

Add <code> Some Code </code> by using this tags.

*
*