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/Servicesfrom 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.
3 Comment(s)
Feb 19
at 1:39
Very helpful, thanks!
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.
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.