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

Save the file.

About Ricard Torres

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

@ricard_dev @ricard_dev

📝 Blog 🎙 Podcast

Leave a Reply

Add <code> Some Code </code> if you need to.