3.30.2012

Mac OS X Keychain Annoyances

No time today to work on my Mac SOE more on Monday. Just a quick snippet (which I actually use in my Mac SOE image).

We use Active Directory, we have our accounts set to expire after a certain period of time. For one reason or another when the Mac end user changes their AD their Keychain password gets out of sync.

This causes any app that had the password saved in keychain to prompt the user to unlock keychain every time they open the app.

I could show them how to manually open the Keychain assistant and reset the password (and I have on many many many occasions) but this is too hard for most of them ;) I give them this little applescript to kill it.

Not the best solution as they lose their keychain passwords, but its the simplest. Here's the applescript.
set FDATE to do shell script ("/bin/date '+%Y-%m-%d-%H%M%S'")

try
 set status to display dialog "Clear Keychain." & return & return & "What you are about to do is potentially destructive, please close all applications before proceeding." buttons {"Continue", "Quit"} default button 1 with icon stop

 set response to button returned of status
 
 if response is equal to "Continue" then
  try
   do shell script ("/bin/mv -f ~/Library/Keychains/login.keychain ~/Library/Keychains/login.keychain." & FDATE)
  end try
  try
   do shell script ("/bin/mv -f ~/Library/Keychains/metadata.keychain ~/Library/Keychains/metadata.keychain." & FDATE)
  end try
  set status to display dialog "Complete" & return & return & "You must reboot now." buttons {"OK"} default button 1 with icon stop 
 end if
 
end try

When the end user next logs they will be prompted to create a new keychain.