Last active
November 14, 2018 00:43
-
-
Save jarrodldavis/875cd5e844106a19ec1a7b7e95863b02 to your computer and use it in GitHub Desktop.
Extract Safari Passwords
This file contains hidden or 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
global _preferences, _safari, _systemEvents, _passwords, _passwordsLocked, _passwordPrompt | |
-- BEGIN customization points | |
--- Change the following global variables as needed for localization | |
set _preferences to "Preferences…" | |
set _safari to "Safari" | |
set _systemEvents to "System Events" | |
set _passwords to "Passwords" | |
set _passwordsLocked to "Passwords Are Locked" | |
set _passwordPrompt to "Enter password for the current user:" | |
--- Change this handler to customize CSV rows | |
to buildCsvRow(_website, _username, _password) | |
return "\"" & _website & "\",\"" & _website & "\",\"" & _username & "\",\"" & _password & "\"" | |
end buildCsvRow | |
-- END customization points | |
set AppleScript's text item delimiters to " " | |
tell application "System Events" | |
tell process _safari | |
click menu item _preferences of menu _safari of the first menu bar | |
set _preferencesWindow to the first window | |
tell _preferencesWindow's first toolbar to click button _passwords | |
set _passwordsGroup to the first group of _preferencesWindow's first group | |
my unlock(_passwordsGroup) | |
set _csv to my getPasswords(_passwordsGroup) | |
set the clipboard to _csv | |
display alert "Passwords copied to clipboard as CSV" | |
end tell | |
end tell | |
to unlock(_passwordsGroup) | |
tell application "System Events" | |
tell _passwordsGroup | |
repeat until not (exists static text _passwordsLocked) | |
set _passwordAnswer to display dialog _passwordPrompt default answer "" with hidden answer | |
my activateSafari() | |
tell the first text field | |
set focused to true | |
repeat until focused is true | |
delay 0.1 | |
end repeat | |
keystroke _passwordAnswer's text returned | |
confirm | |
end tell | |
end repeat | |
end tell | |
end tell | |
end unlock | |
to getPasswords(_passwordsGroup) | |
activateSafari() | |
tell application "System Events" | |
set _table to the first table of _passwordsGroup's first scroll area | |
set _rows to every row of _table | |
set _csv to "" | |
repeat with i from 1 to the number of _rows | |
set _row to item i of _rows | |
tell _table to select _row | |
set _websiteUI to the first static text of first UI element of _row | |
set _website_desc to the description of _websiteUI | |
set _website to the first item of every text item of _website_desc | |
set _usernameUI to the first static text of the second UI element of _row | |
set _username to the value of _usernameUI | |
set _passwordUI to the first static text of the third UI element of _row | |
set _password to the value of _passwordUI | |
set _csvRow to my buildCsvRow(_website, _username, _password) | |
set _csv to _csv & "\r\n" & _csvRow | |
end repeat | |
return _csv | |
end tell | |
end getPasswords | |
to activateSafari() | |
tell application _safari to activate | |
end activateSafari |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment