Lock your Mac and Display Fast User Switching Screen on Idle

June 5, 2009 in How-To by Mark

Since I have converted from PC to Mac I have missed the function in Windows that automatically locks the computer and prompt you back to the account login screen. There are various ways to do this on your Mac, however my requirements were the following:

1. Automatically lock the computer via idle time.
2. Prompt Fast user switching/user login window.

So this is my solution I came up with that fits my requirements. If you share your mac with your kids, or others, this is a great solution.

Lets get started.

Step 1: Enable Fast User Switching

Open System Preferences > Accounts

Unlock the options (if neccessary) and select the Enable fast user switching option.


Step 2: Disable Require Password

Open System Prefernces > Security

Uncheck the Require password to wake this computer from sleep or screen saver.

This has to be disabled as it will conflict with this hack.


Step 3: Download and Install SleepWatcher

Navigate to http://www.bernhard-baehr.de/ and download the latest version of SleepWatcher.

Install sleepwatcher.pkg and SleepWatcherStartupItem.pkg


Step 4: Edit the rc.sleep file

I will be using Textmate to edit files, I suggest buying TextMate if you dont already have it. Its a MUST have tool for your Mac.

Open Terminal and type:

mate /etc/rc.sleep
nano /etc/rc.sleep

Add the following text at the bottom of rc.sleep

/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend

Save rc.sleep (it may prompt for your admin password)


Step 5: Edit SleepWatcher

Navigate to /Library/StartupItems/SleepWatcher/ and open the SleepWatcher unix app in TextMate


Step 6: Set the Timeout in SleepWatcher unix app

/usr/local/sbin/sleepwatcher -d -V -s /etc/rc.sleep -w /etc/rc.wakeup

/usr/local/sbin/sleepwatcher -d -V -s /etc/rc.sleep -w /etc/rc.wakeup -t 6000 -i /etc/rc.sleep

Note: Change the value 6000 to your desired timeout time. 600 = 1 minute, so 6000 = 10 minutes.
PS: Set the time to 600 or 1200 if you want to test, otherwise you will be waiting 10 mintues to see if your hack worked.

Save the SleepWatcher file by navigating to /Library/StartupItems/SleepWatcher/ and overwriting the SleepWatcher unix app.


Step 7: Adjust ScreenSaver + Screen Sleep + Reboot

During testing be sure to adjust your screensaver and screen timeout/sleep to a time that is greater than what you set for SleepWatcher.

Reboot your Mac and wait unitl the idle time activates and your screen locks via the Fast user switching login screen.