When you leave your Mac, in the work place for example, you should lock it and return to the login page. This is an added security measure to stop unwanted usage on your Mac. On a Windows PC this come in the handy short cut Windows Key + L. This feature, however, is not present on your Mac. With a little bit of work and a small automator workflow we can automate this process, and then attach it to a keyboard shortcut. It is a quick way to lock your Mac.
Build The Automator Work Flow
To enable us to lock your Mac with a keyboard shortcut, the quickest way to build an automator workflow. Unfortunately there is no built in method for automatically do this. However, the automator workflow is simple and only calls a one line Terminal command.
Open automator within your Applications folder. When the pop up appears asking you which option you would like, select Service. This workflow will build a workflow which will also allow you to lock your Mac from the services menu.
When the workflow opens. Set the settings at the top of the menu to ‘Service Receives: No input’, this is because the application doesn’t require anything to run, setting this option to something else will force the service into expecting a file or application. We don’t want that to happen.
The next step is to add the little bit of Terminal code that will run our command to lock your Mac. From the library search for ‘Run Shell Script’. Then copy and paste the following into the text box.
/System/Library/CoreServices/"Menu Extras"/User.menu/Contents/Resources/CGSession -suspend
If you want to test this command, open Terminal within your Utilities folder and copy and paste the code into the window. When you hit enter you will notice that your Mac will return to the login screen.
Hit save and give it a name such as ‘Lock Your Mac’, note that this will appear in your Service menu, so name it appropriately.
Lock Your Mac With A Keyboard Shortcut
We now have your Service, you can test it out from your service menu. To give it a keyboard command or shortcut we can do this with System Preferences.
Open System Preferences and then the Keyboard preference pane. Then select the ‘Keyboard Shortcuts’ tab. This is where you can select and change many of the system keyboard shortcuts. Select the services option from the right hand side, then scroll down the list to the general services. This is usually at the bottom and you will notice that the ‘Lock Your Mac’ service which we just creates is present.
Press the ‘add shortcut’ button and then press the keys you want to use to lock your Mac. Something like Command + L (similar to Windows + L) is probably taken already, so add an alt or option key to ensure the command isn’t taken by something else. You can immediately test this out. If you see your login screen you have successfully locked your Mac.
This system is a little bit long winded. I have yet to find a better one.
Once you have set this up you area ready to go. You can lock your Mac with a keyboard shortcut and get to your locked, login, screen within seconds.