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
I want to thank you @macpwd, your script works perfectly.
For those who have issues with it, I figured the script doesn't work properly if you have passwords with missing username or password.
Try to clean your list first (who needs passwords without password) or sort them so that the lines without password or username comes at the end. Then run the script as explained and it should be ok.
I used it for Bitwarden.
You will need to remove all the quotation marks from your csv (using "find and replace", make sure you don't have passwords using them), your output will then become like this
website,username,password
In order to import it to Bitwarden you have to add the following line on top of the other ones
login_uri,login_username,login_password
Then paste the whole csv text into Bitwarden import tool selecting "Bitwarden (csv)" as the format of imported file.
You will miss the "name" field for all of your passwords indeed, but you can fix this if you know some Excel tricks and add "name" in the first line of your csv.