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
- Open ‘Automator’ from your ‘Applications’ folder
- When asked to choose a type for your document, pick ‘Service’ and proceed
- From the library of actions (left side), choose ‘Run AppleScript’ from ‘Utilities’ and drag it to the right side of the window
- Make sure you chose ‘Service receives no input in any application’ in the drop-down menu on the top
- 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
- Save everything under a name of your choice (it will reside in ~/Library/Services from now on)
Assigning a shortcut
- Open ‘Keyboard’ from the ‘System Preferences’
- Go to the ‘Keyboard Shortcuts’ tab and choose ‘Services’ on the left side
- 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
- 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)
- 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.