I'm a new 1Password user and recently tried to export all my passwords saved in iCloud Keychain to import them in 1Password. Unfortunately, none of the existing recipes worked for me, because moving the saved passwords from iCloud Keychain to a local keychain seems to be broken as of today (28 Aug 2018). So I came up with a different method.
This method works entirely using AppleScript, and only for website passwords (not for other kinds of logins such as file servers, etc.). Basically, the script toggles back and forth between Safari's Preferences window and TextEdit, copying each username and password combination via the clipboard.
Full instructions:
- If you have iCloud Keychain enabled, you might want to disable it temporarily, so that on the off chance that your passwords get corrupted, the changes won't propagate to the cloud.
- Make sure you have an up-to-date backup of your computer, including the keychain.
- Ensure that automatic backups are turned off, so that the plain text file we're going to create containing your passwords won't end up being backuped.
- Open Script Editor, and create a new file.
- Paste the contents attached below.
- Go to System Preferences -> Security & Privacy -> Privacy -> Accessibility, and make sure that Script Editor is allowed to control the computer.
- Open TextEdit and create a new file.
- Select Format -> Make Plain Text.
- Save the file as "Passwords.csv" (or any other name, the .csv extension is what is important).
- Make sure that file is the only open file in TextEdit.
- Open Safari, and make sure all its windows are closed.
- Open Safari -> Preferences, navigate to the Passwords tab, and enter your password to unlock the list.
- Select the first item in the list. This will be the first item imported to the text file, and the script will work its way down.
- Go back to Script Editor and press the play button.
This should import the first 5 passwords. When it's done, go to TextEdit and verify the contents. They should be in the format that 1Password expects for CSV files: name, URL, username, password. (Since there are no names for password items in Safari, this script just uses the URL as the name, so the first two fields will be identical.)
If you are confident the passwords got exported correctly, do the following to export the next batch of passwords:
- In TextEdit, ensure the caret in the text file is at the end of the file, on a line of its own.
- Go to Script Editor, adjust the command "repeat 5 times" to however many passwords you want to process at a time (say, 100, depending on how many you have). If you don't have that many passwords in Safari, it will keep exporting the last list entry, so no harm will be done except for a few duplicate lines in the text file, which you can delete manually after you're done. Be careful with selecting a very high number of repetitions though, because it's hard to stop the script once it's running.
- Save the script.
- Go to Safari, and make sure the passwords are still unlocked (Safari tends to auto-lock them after a few seconds), and that the next list item you want to export is selected. Be sure not to change the sort order of the list while going through this procedure, or you may end up with some passwords lost and some duplicate.
- Go back to Script Editor and press the play button.
This should export the next batch of passwords into the file. Repeat this as often as necessary.
After you've imported the file into 1Password, don't forget to turn backups back on, re-enable iCloud Keychain, and/or un-allow Script Editor to control your computer.
Script contents to paste into Script Editor:
repeat 5 times
tell application "Safari"
activate
delay 0.4
tell application "System Events" to keystroke "\t"
tell application "System Events" to keystroke "c" using command down
end tell
tell application "TextEdit"
activate
delay 0.4
tell application "System Events" to keystroke "\""
tell application "System Events" to keystroke "v" using command down
tell application "System Events" to keystroke "\",\""
tell application "System Events" to keystroke "v" using command down
tell application "System Events" to keystroke "\",\""
end tell
tell application "Safari"
activate
delay 0.4
tell application "System Events" to keystroke "\t"
tell application "System Events" to keystroke "c" using command down
end tell
tell application "TextEdit"
activate
delay 0.4
tell application "System Events" to keystroke "v" using command down
tell application "System Events" to keystroke "\",\""
end tell
tell application "Safari"
activate
delay 0.4
tell application "System Events" to keystroke "\t"
tell application "System Events" to keystroke "c" using command down
tell application "System Events" to keystroke "\t"
tell application "System Events" to key code 125
end tell
tell application "TextEdit"
activate
delay 0.4
tell application "System Events" to keystroke "v" using command down
tell application "System Events" to keystroke "\""
tell application "System Events" to keystroke return
end tell
end repeat
For those that could not use the previously posted scripts to Export passwords from Safari, because the script was copying only passwords, or only usernames and passwords without the site name - below is the version that worked for me in Safari 14.0.1 on MacOS Mojave 10.14.6.
Instead of opening a pop-up that seems to be changing UI from time to time, the script utilizes three available context menu actions: Copy Website, Copy User Name, Copy Password. Basically that's all the information you have in the Safari password storage, so script takes that and adds it to open csv file in TextEdit in csv format. You may then copy info from there using excel and paste into a template
csv file of your choice (1password, dashlane, lastpass etc.) enriching with additional data as needed.
Again, pre-requisites are:
Execution:
"website.com","user_name","pa$$word"
A reminder: resulting file that you get is just a plain-text list of all your accounts and passwords. Use it immediately to import the data into the password manager of your choice, and then erase completely(!) from your system. If you are not ready to run the import yet - just delete it (from trash too!) now, and once you ready to run the import - run the script again to extract passwords from Safari.