Created
February 25, 2021 21:02
-
-
Save anthonygelibert/29ec586e02ad80a804bd7e22f1bff78b to your computer and use it in GitHub Desktop.
Export Safari ReadingList
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
#!/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