Switch to login window upon sleep

Jul 28, '04 10:32:00AM

Contributed by: aglzen

As the proud owner of a new 12" powerbook, I immediately wanted one feature lacking in Mac OS X: the ability to have a secure screen lock upon closing the lid. There has been some discussion on this site of how to "fast user switch" to the login screen on screensaver activation, but this wasn't really what I was looking for. When the screensaver is on, I can be reasonably sure I'm near my notebook. But when I close it, drop it in its case, and head out -- that's when we could get separated.

Looking through this site, I found part of the solution in this hint. The trick was getting this script to activate on Sleep (or wake up). After some searching, I found Bernhard Baehr's excellent Sleepwatcher. Sleepwatcher is a daemon that calls a pair of scripts, ~/.sleep and ~/.wakeup, upon sleep and wakeup. Combining these two, I installed Sleepwatcher, and used the code below as my .sleep file (the /System... line is shown on two lines; enter it as one line without any added spaces):

#!/bin/sh
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/
 Resources/CGSession -suspend
Restart, and your Mac will fast-user switch itself to the log in screen when you close the lid! Hope this helps other paranoid PowerBook owners! Note: You can also put this script in your .wakeup file, but there's a few (three to five) seconds' delay between wake and the script call, leaving the system wide open for a few seconds, and looking a bit tacky to boot.

[robg adds: I tested this one with our iBook, and it worked exactly as described. Make sure you remember to make the script executable (chmod +x .sleep). It's pretty cool; close the lid, and next time you open it, you're at the login screen, but still logged in thanks to fast user switching.]

Comments (62)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040724203315798