Converting Safari cookies.plist to cookies.txt

wget is great for resuming downloads, something that no browser handles correctly. It has a very handy option, --load-cookie-file, which takes a cookies.txt style file from your browser and correctly serves it to the web server you’re connecting to. This is useful so you can download files where you have to log in first.

But of course, Safari doesn’t use the cookies.txt file format. Fortunately, Ruby and the plist gem come to the rescue.


$ sudo gem install plist
$ irb
>> require 'plist'
>> result = Plist::parse_xml("Library/Cookies/Cookies.plist")
>> File.open("cookies.txt", "w") {|f| result.each {|r| f.write("#{r["Domain"]}\tTRUE\t#{r["Path"]}\tFALSE\t#{r["Expires"].strftime("%s")}\t#{r["Name"]}\t#{r["Value"]}\n")}}

4 Responses to “Converting Safari cookies.plist to cookies.txt”

  1. spike says:

    Dude. thanks. this saved my life.

    I really didn’t feel like coding this myself today.

  2. Stefan says:

    Awesome, exactly what i needed!

  3. Joe says:

    It’s so annoying that it’s simpler to just install Firefox and the Cookie Export plugin for the few sites that you need the cookies from. Apple, Google and Opera need to make it simpler.

    Thanks for the script, though. It is useful and doesn’t make us install an entire program just to get this feature!

  4. Nathan says:

    Thanks for this! I’m working on a Google Voice notifier and don’t need to write a login system now!

Leave a Reply