RSS - A Better Way to Process My Feed

Well I have an item called “Feeds” in my Safari Bookmarks Bar. If it has a number in parenthesis next to its name then I know for sure that a new RSS feed is in. Looking at the menu items in this menu I can see which feed has a new item because Safari also puts a number against it’s title. If I click on that item I’ll get a page for that feed, listing every item.

Well, that’s my plan of attack to use UI scripting to automatically handle the feed. I’ll probably throw up an Apple Script “say” at a loud volume but I might also be brave and, because this particular feed is alerting me to a new file able to be downloaded, I’ll let the script download the file, sight unseen.

All through Safari UI scripting. :frowning:

My question (took my time didn’t I…): Is there a better way to monitor RSS feeds and then do whatever, without resorting to UI scripting? I still think that UI scripting is very much a hack and thus liable to be broken with software updates, for example.

By the way: I can get to identifying that I have a new feed, but actually “parsing” the data is another problem I’ll get to another time here, if necessary. I couldn’t find anything searching for “RSS” in this forum, which surprised me. Everything else is here :smiley:

Hi Harrogath,

When it comes to processing RSS feeds, I like to make use of DEVONagent’s (or DEVONthink’s) AppleScript dictionary, which features some very powerful commands.

http://www.devon-technologies.com

For example, the following code will read an RSS feed and create a record of feed articles where you can query the following keys: title, link, date, description, content, author, and corresponding HTML code.


tell application "DEVONagent"
	set feedsource to download markup from "feed://www.apple.com/main/rss/hotnews/hotnews.rss"
	set feeditems to get items of feed feedsource
end tell
-- returns a nicely structured record of feed articles

Here is a more elaborate example, that shows how to interact with Safari.

The script below will read the URL of a RSS feed currently open in Safari (for demonstration purposes only, I open the Apple Hot News RSS feed) and then process it with DEVONagent’s «get items of feed» command. It searches the single articles of the feed for the keyword ‘Apple’ (titles & descriptions) and opens matching articles in a new tab in Safari.


tell application "Safari"
	make new document with properties {URL:"feed://www.apple.com/main/rss/hotnews/hotnews.rss"}
	delay 3
	set feedurl to URL of document 1
end tell

tell application "DEVONagent"
	set feedsource to download markup from feedurl
	set feeditems to get items of feed feedsource
	repeat with feeditem in feeditems
		if |title| of feeditem contains "Apple" or description of feeditem contains "Apple" then
			tell application "Safari"
				tell window 1
					make new tab with properties {URL:link of feeditem}
				end tell
			end tell
		end if
	end repeat
end tell

Maybe you an also make good use of DEVONagent’s AppleScript dictionary.

Now back to breakfast :smiley: