Skip to content

Instantly share code, notes, and snippets.

@shane1027
Last active March 18, 2024 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shane1027/8687c2ea90efaa6d50307bb489f0ab8b to your computer and use it in GitHub Desktop.
Save shane1027/8687c2ea90efaa6d50307bb489f0ab8b to your computer and use it in GitHub Desktop.
export safari reading list items to text file on macos
import os
import plistlib
INPUT_FILE = os.path.join(os.environ['HOME'], 'Library/Safari/Bookmarks.plist')
OUTPUT_FILE = 'readinglist.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