AppleScript - replacing passwords

Aug 08, 2011 10:58

Here's an AppleScript that I'm using to replace a bunch of passwords every month. The corporate network expires passwords after a month, so I have to go through all my keychain items to replace the stored password (as opposed to remembering the password and using it dozens of times a day).



on run {input, parameters}
delay 1
tell application "System Events"
set downArrow to ASCII character 31
-- Select the password and paste new one
keystroke "a" using command down
keystroke "v" using command down
keystroke "s" using command down
keystroke "w" using command down
-- Select the next keychain entry, show info
keystroke downArrow
keystroke "i" using command down
-- shift Tab
keystroke " " using shift down
-- space
keystroke " "
end tell
return input
end run

Put that in a "Run AppleScript" Automator Workflow element, set a keyboard shortcut, and off you go:
  • Search for the keychain items you'll need to replace passwords for (i.e.: the corporate login)
  • Open the first one, replace the password (using e.g.: the key generator built into Keychain Access)
  • Copy that password to the clipboard (i.e.: ⌘C)
  • Invoke the Service shortcut you have defined

The script will select all, paste, save, close, then open the next keychain item, tick the box to "show password", and leave you to enter the keychain password if required (to unlock the item so you can view the password) and tab into the password field. Now invoke the service again.

One day I'll see if Keychain Access can respond to events that will let the script be clever about tabbing into the password field if required.

PS: You will need to turn on "Full Keyboard Access: All controls" in the Keyboard preferences pane. This allows the ⇧tab to select the "show password" checkbox.

applescript, engineers-log, programming, productivity, mac os x

Previous post Next post
Up