Skip to content

Instantly share code, notes, and snippets.

@Yevgnen
Created August 28, 2020 06:53
Show Gist options
  • Save Yevgnen/b420a4fa7f9c37e8ca72f973346fe95c to your computer and use it in GitHub Desktop.
Save Yevgnen/b420a4fa7f9c37e8ca72f973346fe95c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
export_safari_reading_list.py
~~~~~~~~~~~~~~
This script gets a list of all the URLs in Safari Reading List, and
writes them all to a file.
Requires Python 3.
"""
import os
import plistlib
INPUT_FILE = os.path.join(os.environ["HOME"], "Library/Safari/Bookmarks.plist")
OUTPUT_FILE = "safari_reading_list.txt"
# 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 = (bookmark["URLString"] for bookmark in bookmarks)
# Write the URLs to a file
with open(OUTPUT_FILE, "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