6

I just have a billion items in Safari's reading list and I would like the links to all of them.

Is there a way to get all of the items in your reading list as links (maybe in a text document)?

3

3 Answers 3

9

I whipped up a Python script to read the plist file referenced in the question patrix mentioned in the comments.

#!/usr/bin/env python
import plistlib
from shutil import copy
import subprocess
import os
from tempfile import gettempdir
import sys
import atexit

BOOKMARKS_PLIST = '~/Library/Safari/Bookmarks.plist'
bookmarksFile = os.path.expanduser(BOOKMARKS_PLIST)

# Make a copy of the bookmarks and convert it from a binary plist to text
tempDirectory = gettempdir()
copy(bookmarksFile, tempDirectory)
bookmarksFileCopy = os.path.join(tempDirectory, os.path.basename(bookmarksFile))

def removeTempFile():
    os.remove(bookmarksFileCopy)

atexit.register(removeTempFile) # Delete the temp file when the script finishes

converted = subprocess.call(['plutil', '-convert', 'xml1', bookmarksFileCopy])

if converted != 0:
    print "Couldn't convert bookmarks plist from xml format"
    sys.exit(converted)

plist = plistlib.readPlist(bookmarksFileCopy)
 # There should only be one Reading List item, so take the first one
readingList = [item for item in plist['Children'] if 'Title' in item and item['Title'] == 'com.apple.ReadingList'][0]

if 'Children' in readingList:
    for item in readingList['Children']:
        print item['URLString']

Copy and paste that into a file, name it something like readinglisturls.py. Then make it executable by running chmod +x readinglisturls.py in the Terminal. Then you can run it in the Terminal and it will print out any Reading List URLs. If you want the URLs in a file, you can redirect the output to a file by running /path/to/readinglisturls.py > myfile.txt in the Terminal.

1
2

Another option using the plist Ruby gem:

sudo gem install plist;plutil -convert xml1 -o - ~/Library/Safari/Bookmarks.plist|ruby -rubygems -e 'require "plist";puts Plist.parse_xml(STDIN.read)["Children"].select{|e|e["Title"]=="com.apple.ReadingList"}[0]["Children"].map{|e|e["URLString"]}'

Or if you don't have other bookmarks:

defaults read ~/Library/Safari/Bookmarks.plist | sed -En 's/^ *URLString = "(.*)";/\1/p'

1

Here's a version using the Factor programming language that is a bit simpler than the Python version answered already in this post:

: reading-list ( -- urls )
    "~/Library/Safari/Bookmarks.plist" read-plist
    "Children" of [ "Title" of "com.apple.ReadingList" = ] find nip
    "Children" of [ "URLString" of ] map ;

More information is available in this blog post.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .