How can I list all my passwords stored in Keychain Access?

I am trying to use the 'security find-internet-password' command to show my passwords. I want to write a script to loop through my keychain and list all of my passwords. I have read the man page for security and tried the examples but cannot get it to return any of my passwords.

Here is the command from the man page:

find-internet-password [-h] [-a account] [-s server] [options...] [-g] [keychain...]
            -a account      Match account string
            -c creator      Match creator (four-character code)
            -C type         Match type (four-character code)
            -d securityDomain
                            Match securityDomain string
            -D kind         Match kind string
            -j comment      Match comment string
            -l label        Match label string
            -p path         Match path string
            -P port         Match port number
            -r protocol     Match protocol (four-character code)
            -s server       Match server string
            -t authenticationType
                            Match authenticationType (four-character code)
            -g              Display the password for the item found
            -w              Display the password(only) for the item found

I have tried several syntaxes for the command including leaving the keychain value blank. in the below examples admin is a account name for one of my internet accounts. I would prefer to be able to get all of the passwords at once but when I dump-keychain it gives an unreadable mess of text with lots of tags that I cannot parse. Is there any

$ security find-internet-password -a admin -g 
$ security find-internet-password -a admin -g login
$ security fine-internet-password -a admin -g user
$ security find-internet-password -a admin -g /Users/Chilly/Library/Keychains/user

I would prefer to be able to get all of the passwords at once but when I dump-keychain it gives an unreadable mess of text with lots of tags that I cannot parse. Is there any documentation on the web for the format of that dump file or how to parse it. Suggestions I have seen say to just 'grep' the file but I need documentation to know what to look for. (and to read a manual on grep and awk and sed but those are widely available:-)


Solution 1:

This will dump your login passwords:

sudo security dump-keychain -d login.keychain > keychain.txt

And this is a script that can convert it to a human readable format: https://gist.github.com/rwest/1583781

NB: The Ruby script worked for me only after I removed the line containing .gsub!('htps', 'https');.

And, optionally, here is an applescript which will autoclick for you the OS security confirmation dialog: https://apple.stackexchange.com/a/137336/66812.