Screen lock keyboard shortcut for your Mac

I’ve always been slightly annoyed by the lack of a key­board short­cut to lock the screen on my Mac. There are sev­eral pop­u­lar solu­tions out there (screen­saver acti­vated by hot cor­ners, a lock icon in menu bar, etc), but I really missed my Windows-style Win­dows key+L key­board short­cut. I’ve finally found a suit­able solu­tion with a com­bi­na­tion of a Ter­mi­nal com­mand and Quick­sil­ver’s trig­ger functionality.

Command-line script

It turns out there’s a sim­ple ter­mi­nal com­mand to do exactly what we want. The fol­low­ing com­mand will hide your desk­top con­tents and dis­play a login win­dow (along with a fancy screen-rotating animation).

Open your favorite text edi­tor and save a file called lockscreen with the con­tents below. I saved mine in a direc­tory called ~/bin/, but you can put yours any­where. (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 exe­cutable. In Ter­mi­nal, type:

chmod 754 ~/bin/lockscreen

Set up a Quick­sil­ver trigger

The built-in key­board short­cut sys­tem in OS X can’t eas­ily trig­ger a command-line script like our lockscreen script. We’ll set up a trig­ger in Quick­sil­ver to accom­plish the same effect.

In Quick­sil­ver, go to the Cat­a­log and add a your lockscreen script.

Next, go the Trig­gers sec­tion in Quick­sil­ver. Add a new HotKey under the Cus­tom Trig­gers sec­tion. Type lockscreen under ‘Select an item’ and click Save (it should auto­mat­i­cally find this from the cat­a­log). Then click on the Trig­ger col­umn to set the key­board short­cut. I went with Ctrl+Option+Command+L, but choose whichever com­bi­na­tion you like.

That’s it—close the Quick­sil­ver win­dow and try out your new key­board shortcut!

1 comment

  1. […] ver­sion from here) Pub­lished in […]

Comment on this post

You may use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>