Skip to content

Instantly share code, notes, and snippets.

@johnpc
Last active November 9, 2019 17:18
Show Gist options
  • Save johnpc/1874803062e9a5d8352e66b73305b5dd to your computer and use it in GitHub Desktop.
Save johnpc/1874803062e9a5d8352e66b73305b5dd to your computer and use it in GitHub Desktop.
Import safari passwords from csv
tell application "Safari"
activate
end tell
tell application "System Events" to tell application process "Safari"
set frontmost to true
keystroke "," using {command down}
set tb to toolbar 1 of window 1
set buttonName to (name of button 4 of tb as string)
click button 4 of tb
set theResult to display dialog "Please unlock " & buttonName & " and press Continue when unlocked" buttons {"Cancel", "Continue"} default button "Continue"
if (button returned of theResult) is "Cancel" then
error number -128
end if
tell application "System Events" to tell application process "Safari"
set frontmost to true
end tell
set prefsWin to window 1
-- set theTable to table 1 of scroll area 1 of group 1 of group 1 of prefsWin
set addButton to button 3 of group 1 of group 1 of prefsWin
-- Add the passwords
set DELIM to {","}
set acsv to (choose file)
set csvList to read acsv using delimiter linefeed
set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, DELIM}
repeat with arow in csvList
set ritems to text items of arow
set website to item 2 of ritems
set username to item 3 of ritems
set p to item 4 of ritems
click addButton
set websiteTextField to text field 1 of sheet 1 of window 1
set usernameTextField to text field 2 of sheet 1 of window 1
set passwordTextField to text field 3 of sheet 1 of window 1
set addPasswordButton to button 1 of sheet 1 of window 1
set value of websiteTextField to website
set value of usernameTextField to username
set value of passwordTextField to p
click addPasswordButton
end repeat
set AppleScript's text item delimiters to TID
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment