Home > mac, os x, tips, work > How To: OS X Selective Desktop Lock Hotkey

How To: OS X Selective Desktop Lock Hotkey

November 12th, 2008 Leave a comment Go to comments

yay security!UPDATE: 10.6 users should follow the guide here. 10.5 or below users can follow the guide below.

Despite all the compliments I pile on Mac OS X here, it is missing one feature that can be found on every version of Windows since Windows 2000: A keyboard hot key that locks the desktop regardless of the screen saver’s normal security setting.

Hit the link below for the rest of the guide…

One thing Linux, OS X, and Windows all have in common is a static screen saver lock setting. This setting tells the OS to lock the desktop if the screen saver is ever activated, or to leave it alone and never lock the desktop. In Windows, you can leave the persistent lock setting off and still lock the desktop by pressing the key with the Windows logo on it and L at the same time. I like to think of this as “selective desktop locking”.

I use my Macbook at work every day, but I don’t want it to always lock the desktop whenever the screen saver turns on because I take it home every night.

Surprisingly, after myself and a couple other Mac fans at work spent some time trying to find a solution, there doesn’t appear to be any existing info online covering how to set this up on an OS X system. So the three of us decided to set it up ourselves.

Requirements:
- OS X (written while on 10.5.5, works fine on 10.5.6)
- Quicksilver
- Keychain menu bar icon
- Apple’s Script Editor (you may need to install the Developer Tools from your OS X system discs, not sure though)

To add the Keychain menu bar icon, open the Keychain Access application (found in Applications -> Utilities). Open preferences for the app, and check the box marked “Show Status in Menu Bar”. You should now have a small padlock icon in your menu bar, like so:

Menu Bar Icon

Note the position of the icon (far right). If you want to follow this guide exactly your icon will need to be in the same place, otherwise you will need to modify some of the values in the script below. Hold down the apple button/command button/whatever you want to call it and drag the icon with the mouse to move it.

Now we need to create a script that will do the actual work. Open the Script Editor application (Applications -> AppleScript) and create a new script with the following code:

tell application “System Events”
click menu bar item -1 of menu bar 1 of application process “SystemUIServer”
keystroke (key code 125)
keystroke return
end tell

You should have something that looks like this:

Lock Script

A very special thanks to mark at the osxhints.com forums for helping me figure this part out!

You can save this as either a script or an application and it should still work correctly, however we have seen some odd behaviors from it when saved as a script, so I recommend you save it as an application. Open the File menu and choose Save As. In the window that appears name it whatever you want (I called mine LockDesktop) and change the File Format drop down menu to Application. I have a directory I called Files inside my user directory that I use for items like this one, but you can put it wherever you want.

Now it’s time for some Quicksilver-fu. Open Quicksilver’s preferences and go to the Triggers tab. Click the + button at the bottom of the window and add a new hotkey setup like this:

Click the Save button. Click on your new trigger and then the i icon near the lower right to open the inspector screen. Set a Hot Key (I used ⌘ L).

All done! Close the window (make sure your new trigger is saved and shows up in the list), close the Quicksilver preferences, and test your new hot key. You may need to adjust the variables in the “click menu bar item X of X” line of the script if your keychain icon is not in the far right corner.

One last important item: While this setup replicates selective desktop locking, it is not perfect. Sometimes, especially after a reboot or if you just logged in, the application can take several seconds to launch and run correctly. Subsequent launches will be speedier but can still take a couple seconds to complete.

Questions/comments/etc are welcome, just post a comment here.

Categories: mac, os x, tips, work Tags: , , ,
  1. Moriarty
    January 22nd, 2009 at 05:37 | #1

    You can do the same without the Keychain, by doing:
    /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend

  1. No trackbacks yet.