Re: Factor

Factor: the language, the theory, and the practice.

Reading List

Monday, July 15, 2013

#files #macos

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 Hint linked to a question on 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 "" = ] find nip
    "Children" of [ "URLString" of ] map ;

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

IN: scratchpad reading-list .