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