Last active
August 16, 2022 07:06
-
-
Save mh61503891/2ab93a8226867d3067c362f4053a4213 to your computer and use it in GitHub Desktop.
Exporting URLs from Safari's Reading List via Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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