First open your favorite text editor (Except for TextEdit or Microsoft Word) 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

/bin/sh kill -3 $(ps wax | grep “[T]erminal.app” | awk ‘{print $1}’)

osascript -e ‘tell application “Terminal” to quit’

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!

(Modified version from here)

Published in Technology
  • Mac Tyler
    hey how is everyone doing today lkjasd;flkjasd;lfkj l;ajdf;lkajsdfpiouqwerkl;jas afpoiuqwerlkjsdafpoiuqwr;lkjsad/f.,mxzcv;lkjasdfpoiquwer;lkjasdf/.,masdf;iouzxcv ;lkjasdfoiuqwerlk;jas/df.,mxzcvl;kjasdfpoiuqwer;ljkasdf;lkjasdf;lkjasdf;lkjasdf;lkjasdf;asdf;lkajsdfasfasdfsdfdfdfdfdfdfdfdfdfdfd;lkjasdfoiuqwerlk;jas/df.,mxzcvl;kjasdfpoiuqwer;ljkasdf;lkjasdf;lkjasdf;lkjasdf;lkjasdf;asdf;lkajsdfasfasdfsdfdfdfdfdfdfdfdfdfdfd;lkjasdfoiuqwerlk;jas/df.,mxzcvl;kjasdfpoiuqwer;ljkasdf;lkjasdf;lkjasdf;lkjasdf;lkjasdf;asdf;lkajsdfasfasdfsdfdfdfdfdfdfdfdfdfdfd;lkjasdfoiuqwerlk;jas/df.,mxzcvl;kjasdfpoiuqwer;ljkasdf;lkjasdf;lkjasdf;lkjasdf;lkjasdf;asdf;lkajsdfasfasdfsdfdfdfdfdfdfdfdfdfdfd;lkjasdfoiuqwerlk;jas/df.,mxzcvl;kjasdfpoiuqwer;ljkasdf;lkjasdf;lkjasdf;lkjasdf;lkjasdf;asdf;lkajsdfasfasdfsdfdfdfdfdfdfdfdfdfdfd;lkjasdfoiuqwerlk;jas/df.,mxzcvl;kjasdfpoiuqwer;ljkasdf;lkjasdf;lkjasdf;lkjasdf;lkjasdf;asdf;lkajsdfasfasdfsdfdfdfdfdfdfdfdfdfdfd
  • Mac Tyler
    reply # 2. test
  • Mac Tyler
    Then how does this one work?
  • Mac Tyler
    YOu are an idiot, way to mess up my page. (Testing a reply)
  • Mactyler
    hey what all is going on?
  • ssfkj
    asdfasdfasdfasdf
  • meee
    asdfasdfasdf
  • mactyler
    Reply # 3
  • This is very handy—thanks! Coming from a Windows world to developing on Macs a few years back, I longed for the easy "WinKey + L" to lock my screen. My desk has a Windows laptop, a CentOS desktop, and my favorite MacBook Pro. Now I will have to write/find a script to lock the KDE desktop on CentOS that's as easy!
blog comments powered by Disqus