Mac OS X: Lock your screen with a keyboard shortcut

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/User.menu/Contents/Resources/CGSession' -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.

 

3 Comment(s)

Mohammad

Feb 19
at 1:39

Very helpful, thanks!

Mohammad

Feb 19
at 3:03

Actually I have a complaint/request. When I lock my screen (using the shortcut) the keyboard backlight turns on, and remains on even after logging in. Prior to making/applying the service whenever I started up the computer the light would be on but would shut off after I logged in. Is there another script you might be able to create to prevent the light from turning on at all? Thanks.

chris

Feb 22
at 23:22

I guess there is no way, as this is the same behavior when logging out and then back in again.

Add your comment

Please keep it polite and on topic. Your email address will not be published.

This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)