Screen lock keyboard shortcut for your Mac
I’ve always been slightly annoyed by the lack of a keyboard shortcut to lock the screen on my Mac. There are several popular solutions out there (screensaver activated by hot corners, a lock icon in menu bar, etc), but I really missed my Windows-style Windows key+L keyboard shortcut. I’ve finally found a suitable solution with a combination of a Terminal command and Quicksilver’s trigger functionality.
Command-line script
It turns out there’s a simple terminal command to do exactly what we want. The following command will hide your desktop contents and display a login window (along with a fancy screen-rotating animation).
Open your favorite text editor and save a file called lockscreen with the contents below. I saved mine in a directory called ~/bin/, but you can put yours anywhere. (Note: ignore the text wrap below—there is no line break in the command)
#!/bin/sh
/System/Library/CoreServices/"Menu Extras"/User.menu/Contents/Resources/CGSession -suspend
Now, we have to make the lockscreen file executable. In Terminal, type:
chmod 754 ~/bin/lockscreen
Set up a Quicksilver trigger
The built-in keyboard shortcut system in OS X can’t easily trigger a command-line script like our lockscreen script. We’ll set up a trigger in Quicksilver to accomplish the same effect.
In Quicksilver, go to the Catalog and add a your lockscreen script.
Next, go the Triggers section in Quicksilver. Add a new HotKey under the Custom Triggers section. Type lockscreen under ‘Select an item’ and click Save (it should automatically find this from the catalog). Then click on the Trigger column to set the keyboard shortcut. I went with Ctrl+Option+Command+L, but choose whichever combination you like.
That’s it—close the Quicksilver window and try out your new keyboard shortcut!
1 comment
[…] version from here) Published in […]
Comment on this post