Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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)?

share|improve this question
    
    
Is the 'reading list' plist file the same as the 'bookmarks' plist file? –  Blue Ice Jul 16 '13 at 14:22
    
The reading list entries are stored in the bookmarks file, so yes (kind of). –  patrix Jul 16 '13 at 17:30
add comment

3 Answers 3

up vote 3 down vote accepted

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.

share|improve this answer
    
This script is also available as a Gist on Github, if that’s useful to anyone: gist.github.com/robmathers/5995026 –  robmathers Jul 14 '13 at 17:47
add comment

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.

share|improve this answer
add comment

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'

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.