Advertisements
What's New

Key-chain Script

Keychain Access.app

I used this script when I had a user that always used key chains when saving their passwords, but the problem was when they needed to update their password and their user account did not have admin rights to unlock “Keychain Access.app“. The script will prompt you for the old password and then prompt you again to enter the new password, this will push the new password across the board :). The script was tested on Mac OS X Leopard & Snow Leopard.

set oldPassword to ""
display dialog "Enter the old password you wish to replace in your keychain:" default answer oldPassword buttons {"Cancel", "OK"} default button 2
set oldPassword to the text returned of the result
set newPassword to ""
display dialog "Enter your new replacement password:" default answer newPassword buttons {"Cancel", "OK"} default button 2
set newPassword to the text returned of the result

tell application "Keychain Access" to activate
tell application "System Events"
tell process "Keychain Access"
set theCount to the count of every row of outline 1 of scroll area 1 of splitter group 1 of window "Keychain Access"
repeat with i from 1 to theCount
tell outline 1 of scroll area 1 of splitter group 1 of window "Keychain Access"
tell row i
repeat until exists -- use this delay in case the Keychain Access window is unavailable or accidentally closed
delay 0.2
end repeat
select
end tell
end tell

set thekind to the value of text field 2 of row i of outline 1 of scroll area 1 of splitter group 1 of window "Keychain Access"
if thekind is not equal to "certificate" and thekind is not equal to "secure note" then
click button 2 of splitter group 1 of window "Keychain Access" -- get info for this keychain item
click checkbox "Show password:" of tab group 1 of window 1
tell text field 1 of tab group 1 of window 1
repeat until exists -- if prompted to enter a keychain password, give the user all the time necessary to enter that password
delay 0.2
end repeat
set thePassword to the value
end tell
if thePassword is equal to oldPassword then
--set value of text field 1 of tab group 1 of window 1 to new_password
(* Ran into a bug where if I simply set the value of the text field to new_password the app doesnt' recognize that that the password has been changed... so it doesn't save any changes because it doesn't think any changes have been made.
Needed to use this second approach
*)

set value of attribute "AXFocused" of text field 1 of tab group 1 of window 1 to true
keystroke newPassword

click button 1 of tab group 1 of window 1 -- "Save" (* If make changes and save them, the popup info window will close automatically*)
else
click button 1 of window 1 -- "Close" (* close windows that don't have changes (and don't close automatically) *)
end if
end if
end repeat
end tell
end tell

Advertisements
About BjTechNews (910 Articles)
An IT guy trying to learn everything about technology and sharing it with you all. I'm a blogger and video blogger who highlights daily news in the tech industry, promoting tips and hacks for fellow techies.

Leave a Reply

%d bloggers like this: