The windows world never really got into scripting GUI applications. You get your Visual Basic for Applications in the MS Office tools (and some others), other big apps have their own scripting languages or simple macro languages but it really is a mess since these things pretty much all do their own thing.
Apple has for ages had Applescript. Applescript is a single scripting language that can script any GUI application – as long as the GUI app makes some commands available but most do.
The nice thing about Applescripts is that the runtime requirement is satisfied on all Apple computers even from the old Classic ones. Things have changed a bit but its remained the same basic thing for a long time. The language is very english like and pretty simple to learn, I’ve read a book on the plane back from Helsinki and pretty much jumped right in and wrote something useful.
I use NetNewsWire 2 which is really all you’d want in a RSS aggregator. Specifically I sync all my subscriptions via Bloglines and just subscribe to them in NetNewsWire. The problem is when you do that you do not end up with the same groups or custom names as you have in Bloglines so it is a pain to restructure it all when you need to resubscribe to all your feeds.
So once I did the initial big job of putting all feeds into categories and renaming some – specifically I rename personal blogs to the name of the person rather than whatever people call their blogs – I wanted to export my subscriptions to OPML as a backup. NetNewsWire has a function for this but unfortunately it does not export any Bloglines feeds! Totally useless to me then. Applescript to the rescue.
I will not go through the whole app here, you can get the complete source a bit later, but here are just some snippets and a few words on each to show the basics of scripting with Applescript.
First we tell our script to speak to NetNewsWire and fetch all the group folders.
tell application "NetNewsWire" repeat with curGroup in (every subscription whose is group is true) end repeat end tell
The whose is group is true reads a bit weird, ‘is group’ is a boolean property of each subscription, so the above will loop over all the groups thats been defined.
Next we want to pull out each subscription for the group we are in, so we grow the code to look like this:
tell application "NetNewsWire" repeat with curGroup in (every subscription whose is group is true) set t to display name of curGroup -- put code here to build outline entries for each group repeat with curSub in (every subscription whose display name of group is t) -- put code here to build outline entries for each sub in this group end repeat end repeat end tell
Here I get the display name property of the current group and search for all subscriptions with the same group.
After building the opml file and storing it in a variable I simply chose to output a new TextEdit.app document with the contents of the opml file, but could easily have written a new text file for example
tell application "TextEdit" activate make new document set the text of the front document to opml as Unicode text end tell
Simple stuff, start up the TextEdit application, make it active, create a new document and put the opml file contents into the document as Unicode Text.
So that’s the basic logic, you can get the full script here. This will probably not work 100% with nested groups and I do not cater for subscriptions that does not belong to any group, it works for me though ๐
This is a simple example but it does demonstrate though the absolute beauty of this, data from one app written by one software house queried and modified then output into an app written by another all by a scripting language written by a 3rd, fantastic.