Last active
March 18, 2024 02:27
-
-
Save shane1027/8687c2ea90efaa6d50307bb489f0ab8b to your computer and use it in GitHub Desktop.
export safari reading list items to text file on macos
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
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