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
Hello. Thanks for this.
My only additional pointer is to SORT your Keychain items so that it shows website passwords from the top of the list. Then, like @youniki mentions, shift-select all applicable entries to see the count then paste this into the number of repetitions (REPEATNO). You don't want it taking application/other information, as I've noticed some have encrypted/jumbled lines of text which stretch tens of lines.
If you're using LastPass, here's a guaranteed slightly tweaked script working on MacOS 10.16.6. The only difference to the above scripts is:
You still need to manually set REPEATNO and YOURPASSWORD. Just CTRL+F for these in the script.
Copy everything, including the bits that aren't detected as code
tell application "TextEdit"
activate
tell application "System Events" to keystroke "url,username,password,name"
tell application "System Events" to keystroke return
end tell
repeat REPEATNO times
--URL
tell application "Keychain Access"
activate
tell application "System Events" to keystroke "i" using command down
delay 0.4
tell application "System Events" to key code 48
delay 0.1
tell application "System Events" to key code 48
delay 0.1
tell application "System Events" to key code 48
delay 0.1
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
--USERNAME
tell application "Keychain Access"
activate
delay 0.4
tell application "System Events" to key code 48 using shift down
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
--PASSWORD
tell application "Keychain Access"
activate
delay 0.4
tell application "System Events" to keystroke "c" using {shift down, command down}
delay 0.4
tell application "System Events" to keystroke "YOURPASSWORD"
tell application "System Events" to keystroke return
delay 0.4
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
--NAME
tell application "Keychain Access"
activate
delay 0.4
tell application "System Events" to key code 48 using shift down
tell application "System Events" to key code 48 using shift down
tell application "System Events" to keystroke "c" using command down
end tell
end repeat