Locking your Mac with a keyboard shortcut

This is one feature that isn't directly supported by the otherwise extremely usable OS X.
There are a bunch of ways to do this most involving starting the screen-saver, either though hot corners or via QuickSilver triggers. However, I'm not very happy with starting the screen-saver to lock the screen, so I found the shell command for fast user switching and use that instead. Here's the script:
# lock.sh
/System/Library/CoreServices/"Menu Extras"/User.menu/Contents/Resources/CGSession -suspend
You can execute this script (remember to chmod u+x it first) via a keyboard shortcut by using QuickSilver triggers. Since it's easier to explain with screenshots, that's what I've done. Just remember that when you're selecting an item (shown in the last image), you need to hit '.' to clear the field so you can type in the path to your copy of lock.sh.

4 comments:

Sudhindra Rao said...

Sidu,
What you are doing is too much work.

Try this one instead
http://www.macworld.com/article/49080/2006/01/lockscreen.html

-Sudhindra

Sidu said...

Sudhindra, that's the article that I started my research with. I'm using option 3, fast user switching.

I've tried all the other options but didn't like them much. The only additional thing I'm doing is enabling fast user switching via a keyboard shortcut.

Mayur Wadhwa said...

Neat!

I also found some other script to do this .. I am assuming even using your script the screen saver will come up, if configured such.

"
tell application "ScreenSaverEngine"
activate
end tell
"

Source: http://www.macosxhints.com/article.php?story=20050706194219822

Singletoned said...

I came up with this method:

http://singletoned.net/2008/05/06/lock-a-mac-with-a-keyboard-shortcut/