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_profileCode language: PHP (php)

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'Code language: JavaScript (javascript)

Save the file.

Leave a Reply

Your email address will not be published. Required fields are marked *