Create an Aggregate Feed From All Your NetNewsWire Subscriptions
By Adrian Sutton
I wanted to be able to have all my RSS feeds combined in the cool (looking but totally impractical) RSS screen saver but sadly it only allows you to select one source feed.
I tried two approaches to solve this:
- Set up a personal planet planet instance that aggregates all my feeds and point the screen saver at that.
- Create a combined RSS feed using AppleScript.
Item one I got working but didn’t like the fact that I was then downloading all my RSS feeds twice, so I scrapped the idea. If however you ever want to create a planet instance that stays in sync with your RSS feeds, use something along the lines of the AppleScript below and execute it periodically. I’ve snipped most of the paths involved to try to avoid making the lines too long. A bunch of lines have also been wrapped – the compiler should find them. It reads the configuration file from config.ini.tmpl, adds the RSS feeds to the end and writes it out to config.ini
set theFile to alias "Groovy:...:config.ini.tmpl" set fileRef to open for access theFile set configStart to read fileRef from 0 until (get eof theFile) as string close fileRef set config to configStart tell application "NetNewsWire" set subs to get the subscriptions repeat with sub in subs if the RSS URL of sub as string is not "" then set config to config & "\n" & "[" & the RSS URL of sub & "]" & "\n" & "name = " & the display name of sub & "\n" end if end repeat end tell set fileRef to open for access file "Groovy:...:config.ini" with write permission set eof fileRef to 0 write config to fileRef as string close access fileRef do shell script "cd /.../planet-nightly/; python planet.py aj/config.ini"
The second approach seems to work much better – the AppleScript just creates the combined RSS feed directly. This relies on the first subscription in NetNewsWire being the “All Feeds” item which combines all the feeds together and writes them out to a file. It may be possible to get this to work directly as a CGI script from Apache and output the RSS instead of storing it in a file, but I couldn’t make it work so the script is just run by cron every so often and the output file is stored in /Library/WebServer/Documents/ You’ll probably need to tweak paths and again there’s a bunch of wrapped lines to fix up.
tell application "NetNewsWire" set sub to subscription 1 set entries to "" as string set crlf to "\r\n" repeat with entry in the headlines of sub set entries to entries & "<item>" & crlf & "<title>" & the title of entry & "</title>" & crlf & "<guid>" & the guid of entry & "</guid>" & crlf & ¬ "<link>" & the URL of entry & "</link>" & crlf & ¬ "<description><![CDATA[" & the description of entry & "]]></description>" & crlf & ¬ "<pubDate>" & the date published of entry & "</pubDate>" & crlf & ¬ "<dc:creator>" & the creator of entry & "</dc:creator>" & crlf & ¬ "</item>" & crlf end repeat set header to "<?xml version=" & quote & "1.0" & quote & "?>" & crlf & ¬ "<rss version=" & quote & "2.0" & quote & " xmlns:dc='http://purl.org/dc/elements/1.1/'>" & crlf & ¬ "<channel>" & crlf & ¬ "<title>Planet AJ</title>" & crlf & ¬ "<language>en</language>" & crlf & ¬ "<description>Planet AJ</description>" & crlf set footer to "</channel></rss>" set rss to header & entries & footer end tell set fileRef to open for access file "Groovy:...:rss20.xml" with write permission set eof fileRef to 0 write rss to fileRef as string starting at 0 close access fileRef
The resulting feed isn’t valid but it’s close enough (the dates are in the wrong format and various problems in the source feeds can cause other errors). It seems to work well with the RSS screen saver though and that’s all I needed.