Monday, July 15, 2013

Reading List

The Safari browser has a feature called "Reading List" that makes it easy to synchronize and bookmark pages for later reading. Recently, a Mac OS X Hint linked to a question on stackexchange.com asking how to get Reading List items as links.

The current answer is a Python script that:

  1. Finds the safari bookmarks plist file
  2. Copies the plist file to a temporary file
  3. Converts the plist file from binary to text format
  4. Parses it into a python object
  5. Finds the "Reading List" entry
  6. Prints out the saved URLs

I thought it would be fun to contrast that with a simple solution in Factor.

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

You can try it out in the listener to get something like this:

IN: scratchpad reading-list .
V{
    "http://factorcode.org"
    "http://news.ycombinator.com"
    "http://reddit.com"
}

No comments:

Post a Comment