Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Lock the keychain when the screensaver activates System
I like to have my keychain lock itself when I'm away from the computer so others can't go snooping around where they don't belong. I've tried using the preferences available in Keychain Access, but none of them were able to do what I want, which is to lock the keychain when the screensaver is activated. In Keychain Access, the only option is to have the keychain lock itself after some minutes of inactivity. Unfortunately, this means inactivity within the keychain itself, not inactivity of your computer in general. I didn't want to require a password to exit the screensaver, because sometimes people do need to use my computer (for the net, etc.) so I wrote this little script to lock the default keychain whenever the ScreenSaver is activated. I saved my script as an "application bundle" called "Keychain Locker" (go figure) and then used this hint to hide its dock icon. The script follows...

Enter this in script editor:

on idle
  try
    tell application "Keychain Scripting"
      set KeyName to the name of the current keychain as string
      if locked of keychain KeyName is true then
        return 60
      else if locked of keychain KeyName is false then
        tell application "System Events"
        set prog_list to (get name of every process) as list
        repeat with i from 1 to (count of items in prog_list)
          if item i of prog_list contains "ScreenSaver" then
            tell application "Keychain Scripting"
              lock keychain KeyName
              return 60
            end tell
          end if
        end repeat
      end tell
      return 20
    end if
  end tell
  on error
    display dialog "An error has occured in Keychain Locker" buttons 
    {"Quit"} default button 1
    if the button returned of the result is "Quit" then
      tell me to quit
    end if
  end try
end idle
I also set it as a startup item. I've been using it for weeks and have had no problems. And even at its worst, it takes no more than 2.5% of CPU on my 800 Mhz G4 iMac. Hopefully this can help others who are looking for this functionality.
    •    
  • Currently 2.50 / 5
  You rated: 1 / 5 (4 votes cast)
 
[10,564 views]  

Lock the keychain when the screensaver activates | 9 comments | Create New Account
Click here to return to the 'Lock the keychain when the screensaver activates' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Lock the keychain when the screensaver activates
Authored by: the1truestripes on Feb 09, '04 12:04:38PM

You can also do this with SSHKeychain which will also manage SSH keys (in a way that interacts well with the Terminal app). I'm pretty sure SSHKeychain is not only free, but also GPLed so you can see and mess with the source. Enjoy.

[ Reply to This | # ]

Lock the keychain when the screensaver activates
Authored by: bq on Feb 09, '04 12:54:39PM

If you need to allow people to use your machine while you're away, you can always create a guest account (i.e. username guest, password guest) with restricted access and allow people to use user switching. This accommodates the need for others to use the machine without sacrificing or compromising security.



[ Reply to This | # ]
Hear! Hear!
Authored by: gaudior on Feb 09, '04 01:01:43PM

This is the best option. FUS is quick, and seems to be secure. (I do not know of any exploits.) It's also very simple to set up, and it works for all users on a machine.



[ Reply to This | # ]
Lock the keychain when the screensaver activates
Authored by: asan102 on Feb 09, '04 08:19:36PM

Or better yet, user name Guest, no password. No need to confuse your guests.

However, the username guest is reserved by the system in panther, but If oyu had it in Jaguar it will carry over.



[ Reply to This | # ]
Lock the keychain when the screensaver activates
Authored by: Anonymous on Feb 09, '04 04:25:37PM

Or you could use ScriptSaver.. check on VersionTracker. I think it'll solve this problem much more efficiently than by leaving an AppleScript running in the background.



[ Reply to This | # ]
Lock the keychain when the screensaver activates
Authored by: morgion on Feb 09, '04 08:19:20PM
That script would be the following:

tell application "Keychain Scripting"
	set KeyName to the name of the current keychain as string
	lock keychain KeyName
end tell


[ Reply to This | # ]
Lock the keychain when the screensaver activates
Authored by: dogboy on Feb 10, '04 05:47:49AM

What's wrong with the option in the security pref pane?
You can set it to require a password when woken from screensaver or sleep.
And if you just want to lock your keychain, put the lock icon in the menubar (Keychain app>view>show status in menubar).

It gives a list of keychains which can be locked/unlocked and also the option to lock the screen.



[ Reply to This | # ]
Apple seems to have changed this
Authored by: BrunoUsesBBEdit on Sep 19, '07 09:45:53AM

unfortunately, it seems that now the screensaver lock the keychain with no option to disable this behavior. My screen saver fires all the time while I am reading something, on the phone, on another machine in my cube, or using a hot corner when someone walks into my cube.

I have to enter my password no less than 25 times a day, and that's even if I never leave my cube.

Closed Source, Closed Minds, Missing Opportunities. It really is sad to have such power to make my Linux servers perfectly suited for their tasks, and then have my workstation limited by the imagination of Apple and the freedom they are willing to entrust me with.

---
--==<< R i c h a r d B r o n o s k y >>==-- ---



[ Reply to This | # ]
Apple seems to have changed this
Authored by: luomat on Mar 08, '12 08:39:43AM
I realize this is an old comment, but just in case anyone doesn't know it's wrong, you can control these settings.
  1. Open Keychain Access.app
  2. Make sure you have the 'login' keychain selected
  3. Go to the "Edit" menu and choose "Change settings for keychain 'login'"

And there you can tell it to automatically lock after X number of minutes, or lock when sleeping.

These two screenshots show the menu items and settings I'm talking about:

http://images.luo.ma/Change_Setting_for_Keychain_login-20120308-113308.jpg

http://images.luo.ma/Keychain_Access_login_Keychain_Settings-20120308-113444.jpg


[ Reply to This | # ]