Skip to content

Instantly share code, notes, and snippets.

@anthonygelibert
Created February 25, 2021 21:02
Show Gist options
  • Save anthonygelibert/29ec586e02ad80a804bd7e22f1bff78b to your computer and use it in GitHub Desktop.
Save anthonygelibert/29ec586e02ad80a804bd7e22f1bff78b to your computer and use it in GitHub Desktop.
Export Safari ReadingList
#!/usr/bin/env python3.8
# coding=utf-8
""" Export Safari ReadingList. """
import os
import plistlib
from pathlib import Path
INPUT_FILE = Path(os.environ['HOME']) / 'Library' / 'Safari' / 'Bookmarks.plist'
OUTPUT_FILE = Path('readinglist.txt')
# Load and parse the Bookmarks file
with INPUT_FILE.open('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
reading_list = next(filter(lambda x: x.get('Title', None) == 'com.apple.ReadingList', plist['Children']))
# Extract the bookmarks
bookmarks = reading_list['Children']
# For each bookmark in the bookmark list, grab the URL
urls = (bookmark['URLString'] for bookmark in bookmarks)
# Write the URLs to a file
with OUTPUT_FILE.open('w') as outfile:
outfile.write('\n'.join(urls))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment