Apple - Export iCloud items from Keychain to CSV

A late reply, as I found this post while searching for something related.

You have to create a new keychain, and copy your iCloud keychain items to the new local keychain. Then you can use the security tool to dump them.

Since this is 1Password-related question, for others in the future, you can use MrC's conversion utility to directly convert the keychain dump into a 1Password consumable 1PIF file. It is much better than CSV importing.

https://discussions.agilebits.com/discussion/30286/mrcs-convert-to-1password-utility/p1


I'm on 10.13.6. The MrC's tool, while great for the local keychain, it didn't work for me for iCloud items. Nor did the script to retrieve passwords from Safari.

moxiefrog at 1Password forums posted a solution based on Automator that worked for me. Essentially, this script mimics a user doing copy-paste from each item to a text file.

Below is moxiefrog's code which I have adapted for my macOS version. You may have to adjust the number of tabs (see keystroke tab below), also taking into consideration what fields you would like to copy. As it is, running the script will produce a text file with the following format:

username,website,password

Steps

  1. Open TextEdit and create a new document
  2. Open Keychain
  3. Click on the iCloud keychain and sort it in the order that will be copied to the text document
  4. Locate the line keystroke "password" and insert your password (including the quotes)
  5. Run it once and check if it copied successfully, otherwise you may have to adjust the delay's and/or order and number of tabs.
  6. If everything went fine, increase the repeat value in the first line. Doing batches of 50 is recommended.
  7. Save the text file file as .csv.

Script

repeat 1 times
    delay 0.2
    tell application "Keychain Access"
        activate
        
        tell application "System Events"
            --- Open a keychain item
            delay 0.2
            keystroke return
            --- Press Tab x3
            delay 0.1
            keystroke tab
            delay 0.1
            keystroke tab
            delay 0.1
            keystroke tab
            
            -- Press ⌘C to copy item title
            delay 0.2
            keystroke "c" using command down
        end tell
    end tell
    
    --Switch to TextEdit
    delay 0.2
    tell application "TextEdit"
        activate
        tell application "System Events"
            -- Press ⌘V
            delay 0.2
            keystroke "v" using command down
            
            -- Type a comma
            delay 0.2
            keystroke ","
            
        end tell
    end tell
    
    --Switch to Keychain
    tell application "Keychain Access"
        activate
        tell application "System Events"
            -- Press Tab x2 
            delay 0.1
            keystroke tab
            
            -- Press ⌘C
            delay 0.2
            keystroke "c" using command down
        end tell
    end tell
    
    --Switch to TextEdit
    delay 0.2
    tell application "TextEdit"
        activate
        tell application "System Events"
            -- Press ⌘V
            delay 0.2
            keystroke "v" using command down
            
            -- Type ','
            delay 0.2
            keystroke ","
        end tell
    end tell
    
    --Switch to Keychain
    tell application "Keychain Access"
        activate
        tell application "System Events"
            -- Click the “Show password:” checkbox.
            delay 0.2
            keystroke "c" using {shift down, command down}
            
            -- Type password - update to yours
            delay 0.5
            keystroke "password"
            delay 0.2
            keystroke return
            
            -- Close keychain item window
            delay 0.3
            keystroke "w" using command down
            
            -- Go to next keychain item
            delay 0.2
            key code 125
        end tell
    end tell
    
    --Switch to TextEdit
    delay 0.2
    tell application "TextEdit"
        activate
        tell application "System Events"
            -- Press ⌘V
            delay 0.2
            keystroke "v" using command down
            
            -- Press Return
            delay 0.2
            keystroke return
        end tell
    end tell
end repeat
end run

Disclaimer

Use at your own risk. If you know how to use AppleScript and Automator, then you might be just dangerous enough to screw things up. Good Luck!