Skip to content

Instantly share code, notes, and snippets.

@mh61503891
Last active August 16, 2022 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mh61503891/2ab93a8226867d3067c362f4053a4213 to your computer and use it in GitHub Desktop.
Save mh61503891/2ab93a8226867d3067c362f4053a4213 to your computer and use it in GitHub Desktop.
Exporting URLs from Safari's Reading List via Ruby
# Copy ~/Library/Safari/Bookmarks.plist to ./Bookmarks.plist via Finder
# plutil -convert xml1 -o ./Bookmarks.xml ./Bookmarks.plist
# export-urls-from-safari-reading-list.rb > safari-reading-list.csv
require "bundler/inline"
gemfile do
source "https://rubygems.org"
# https://github.com/patsplat/plist
gem "plist"
end
require "csv"
csv_string = CSV.generate do |csv|
csv << ["title", "url", "created_at"]
plist = Plist.parse_xml("Bookmarks.xml")
plist.dig("Children")[3].dig("Children").each do |e|
title = e.dig("ReadingList", "PreviewText")
url = e.dig("URLString")
created_at = e.dig("ReadingList", "DateAdded")
csv << [title, url, created_at]
end
end
puts csv_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment