Last active
August 17, 2020 16:18
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steps to follow: