Skip to content

Instantly share code, notes, and snippets.

@ibroadfo
Last active September 23, 2018 21:53
Show Gist options
  • Save ibroadfo/97200c641b4dada6185a8b20d5647a8f to your computer and use it in GitHub Desktop.
Save ibroadfo/97200c641b4dada6185a8b20d5647a8f to your computer and use it in GitHub Desktop.
Export Safari Reading List bookmarks to pinboard
#!/usr/bin/env python
"""
forked from http://alexwlchan.net/2015/11/export-urls-from-safari-reading-list/
Requires Python 3.
"""
import os
import plistlib
INPUT_FILE = os.path.join(os.environ['HOME'], 'Library/Safari/Bookmarks.plist')
OUTPUT_FILE = 'readinglist.html'
# Load and parse the Bookmarks file
with open(INPUT_FILE, 'rb') as plist_file:
plist = plistlib.load(plist_file)
# Look for the child node which contains the Reading List data.
# There should only be one Reading List item
children = plist['Children']
for child in children:
if child.get('Title', None) == 'com.apple.ReadingList':
reading_list = child
# Extract the bookmarks
bookmarks = reading_list['Children']
# For each bookmark in the bookmark list, grab the URL
urls = ('<dt><a href="' + bookmark['URLString'] + '">' + bookmark['URIDictionary']['title'] + '</a>' for bookmark in bookmarks)
# Write the URLs to a file
with open(OUTPUT_FILE, 'w') as outfile:
outfile.write('<DT><H3 FOLDED>Reading List (exported)</H3>\n')
outfile.write('<DL><p>\n')
outfile.write('\n'.join(urls))
outfile.write('\n</DL><p>\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment