Mac OS X - Lock your screen with a keyboard shortcut

10 Nov 2011
2 minutes read

This will enable you to lock your screen (by showing the login screen but keeping your session open) with a shortcut of your choice. All without the need to enable “Require password after sleep or screen saver begins” in your System Preferences and will work with Macs without the eject key, e.g. the current MacBook Air.

You will create a tiny Service via Automator, which you can easily assign a shortcut to, via the ‘Keyboard’ settings in your ‘System Preferences’.

Creating a Service

  1. Open ‘Automator’ from your ‘Applications’ folder
  2. When asked to choose a type for your document, pick ‘Service’ and proceed
  3. From the library of actions (left side), choose ‘Run AppleScript’ from ‘Utilities’ and drag it to the right side of the window
  4. Make sure you chose ‘Service receives no input in any application’ in the drop-down menu on the top
  5. Replace (‘Your script goes here’) with the following code:
    do shell script "'/System/Library/CoreServices/Menu Extras/' -suspend > /dev/null" return input
  6. Save everything under a name of your choice (it will reside in ~/Library/Services from now on)

Assigning a shortcut

  1. Open ‘Keyboard’ from the ‘System Preferences’
  2. Go to the ‘Keyboard Shortcuts’ tab and choose ‘Services’ on the left side
  3. Somewhere near the end of the list that shows on the left side, some service with the name you chose when saving your service from Automator will show up
  4. Double click on the far right side of that services name and you can assign a keyboard shortcut of your choice (I chose Ctrl+CMD+L)
  5. Close ‘System Preferences’

That’s it. Now you can easily lock your mac with a keyboard shortcut of your choice without being annoyed by having to type in your password every time your display goes to sleep our your screensaver starts.