A few people have asked me how I lock my screen so conveniently when I walk away from my Mac. Here are two approaches that I’ve used. Both of them have relied on Quicksilver, a wonderfully powerful application that I cannot stand to be without.
Method 1 : Activate the Screen Saver on Hotkey activation.
This one is slightly easier than the login window tip, since it does not require any supporting scripts. There are reasons to prefer one over the other, so I leave the choice to the reader. This one is easy, but requires that you set the security properties so that your screen saver requires a password to disable – otherwise there is no security benefit to this variant.
- Fire up Quicksilver’s Preference panel and select Triggers:
- Create a new item that opens
/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app
when the hotkey is pressed. You will have to navigate to this file in order to have Quicksilver find it. (Start by typing / S y s and navigate the directories.
That’s it. Once you press your hotkey, you should see a little Quicksilver indication and the screen saver will start. Make sure you select a screen saver AND that you have your security settings to request a password to turn off the screen saver.
Method 2 : Activate the Login Window on Hotkey activation.
Using a tiny glue script (in bash, thankyouverymuch), we tell the session manager to suspend the current login session. I do not know if this requires fast-user switching to be activated, but I have it setup on my Mac.
I prefer this one since it uses less CPU and puts the machine in a state where someone else could use it more readily — this is handy at home where the machine is truly multiuser.
- Open the Quicksilver Triggers panel (as above).
- Create
~/bin/LoginScreen.sh. Open Terminal.app and paste this into it:
[ -d ~/bin ] || mkdir ~/bin
cd ~/bin
cat > LoginScreen.sh << EOF
#!/bin/bash
x="/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession"
[ -x "$x" ] && "${x}" -suspend
EOF
chmod +x ~/bin/LoginScreen.sh
If you are familiar with shell scripts and having your own bin directory, feel free to create LoginScreen.sh you own way. You can also just download it here, right click and save as in a well known place.
- Create a hotkey trigger that will launch
LoginScreen.sh.
Navigate to the script (perhaps in ~/bin) and get Quicksilver to launch it when you press the hotkey.
LoginScreen.sh
This is a super simple script to tell the session manager to return to the login screen (suspend the active user's login session).
#!/bin/bash
x="/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession"
[ -x "$x" ] && "${x}" -suspend