Skip to content

Instantly share code, notes, and snippets.

@dhruvkp
Last active August 17, 2020 16:18
Show Gist options
  • Save dhruvkp/ac255de1fd4fd3622519e3595bb5777c to your computer and use it in GitHub Desktop.
Save dhruvkp/ac255de1fd4fd3622519e3595bb5777c to your computer and use it in GitHub Desktop.
Exports safari passwords (iCloud keychain) into csv (importable into chrome). Steps in a comment below.
tell application "Safari" to activate
tell application "System Events" to tell process "Safari"
click menu item "Preferences…" of menu "Safari" of menu bar item "Safari" of menu bar 1 of application process "Safari" of application "System Events"
click button "Passwords" of toolbar 1 of window 1
end tell
tell me
activate
display dialog "You must unlock Safari Passwords window first and then confirm by pressing this button..." buttons {"Quit script", "I have unlocked Safari Passwords window!"}
end tell
tell window "Passwords" of application "Safari" to activate
tell application "System Events"
set filename to "/Users/" & name of current user & "/Desktop/passwords.csv"
tell process "Safari"
set elements to rows of table 1 of scroll area 1 of group 1 of group 1 of window "Passwords" of application process "Safari" of application "System Events"
set num_rows to length of elements
set myFile to open for access filename with write permission
set finalstring to "name,url,username,password" & return
write finalstring to myFile
repeat with i from 1 to num_rows
try
set focused of (text field 3 of row i of table 1 of scroll area 1 of group 1 of group 1 of window "Passwords" of application process "Safari" of application "System Events") to true
set website to value of (text field 1 of row i of table 1 of scroll area 1 of group 1 of group 1 of window "Passwords" of application process "Safari" of application "System Events")
set username to value of (text field 2 of row i of table 1 of scroll area 1 of group 1 of group 1 of window "Passwords" of application process "Safari" of application "System Events")
set passwd to value of (text field 3 of row i of table 1 of scroll area 1 of group 1 of group 1 of window "Passwords" of application process "Safari" of application "System Events")
if website contains " — https" then
set AppleScript's text item delimiters to " — https"
set website to text item 1 of website
set finalstring to website & ",https://" & website & "," & username & "," & passwd & return
else if website contains " — http" then
set AppleScript's text item delimiters to " — http"
set website to text item 1 of website
set finalstring to website & ",http://" & website & "," & username & "," & passwd & return
else
set finalstring to website & ",http://" & website & "," & username & "," & passwd & return
end if
write finalstring to myFile
on error
set errorstring to "Got error at " & i
log errorstring
delay 20
end try
end repeat
close access myFile
end tell
end tell
@dhruvkp
Copy link
Author

dhruvkp commented Aug 10, 2018

Steps to follow:

  • Give assistive access to Script Editor. (From System Preferences > Security & Privacy > Privacy > Accessibility and then add Script Editor by pressing +)
  • Open this script in Script Editor and hit run.
  • A dialog box will appear. Unlock Safari passwords window then press "I have unlocked Safari passwords window" in dialog box.
  • Let it read every password from safari (by keeping the passwords window in focus). This will take some time depending on number of passwords you have.
  • passwords.csv will be stored on your desktop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment