public

MacRuby script to export Safari 5.1 cookies to a human-readable format

  • Download Gist
exportCookies-monkey_patch_edition.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/usr/bin/env macruby
require 'csv'
framework 'Foundation'
 
CSV_Headers = %w[domain path expiresDate name value].to_csv
 
class NSHTTPCookie
def to_csv
[domain, path, expiresDate, name, value].to_csv
end
end
 
def cookie_store
NSHTTPCookieStorage.sharedHTTPCookieStorage
end
 
def cookies_csv
raw_csv = cookie_store.cookies.map(&:to_csv)
raw_csv.unshift(CSV_Headers)
raw_csv.join
end
 
puts cookies_csv
exportCookies.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/usr/bin/env macruby
require 'csv'
framework 'Foundation'
 
store = NSHTTPCookieStorage.sharedHTTPCookieStorage
cookies = store.cookies
 
raw = cookies.map do |c|
[c.domain, c.path, c.expiresDate, c.name, c.value].to_csv
end
 
raw.unshift %w[domain path expiresDate name value].to_csv
 
puts raw.join

TMTOWTDI rocks :)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.