Anybody know how to get RSS articles in Mail.app with Applescript?

It seems that this isn’t as straightforward as it should be.

Hi steffi

not sure of you OS but In OSX 5 you can subscribe to a RSS feed using mail.

http://www.apple.com/macosx/features/300.html

“# RSS
Subscribe to an RSS feed in Mail and you’ll know the moment an article or blog post hits the wire. Even better, you can choose to have new articles appear in your inbox.”

Budgie

What I have is RSS subscriptions in Mail.app and I want to get hold of those messages in Applescript and it’s not as simple as it should be.

Hi Steffi,

As far as I’m aware the only way to do this with applescript is by parsing the items of the folder “~/Library/Mail/RSS”.

What is the end result you want? Do you want access to the text of one item, a list of titles, the URLs or what? If you provide more details we might be able to help more.

See my post in response to a similar question:
http://discussions.apple.com/thread.jspa?messageID=7070047

Thanks

John M
www.nhoj.co.uk

The problem seems to be that you cannot get hold of the RSS articles in Mail.app via applescript

I read this on my iphone which means I have to move them to an IMAP folder first.

Hi Steffi,

I don’t own an iPhone so my opinion may be of limited use.

Mail lets you view RSS items in your inbox. Does this enable them to sync to the phone?

Alternatively, what about a script to write the RSS items to a text file that to open on the phone?

John M

Hi Steffi,

You could use AppleScript code like follows to retrieve the RSS URLs of the feeds subscripted to in Apple Mail and further process them to export them to your iPhone.

For example, DEVONagent’s AppleScript dictionary contains several commands to parse RSS feeds (also used in the example below).

But you could also use a Python script to quickly parse and convert the corresponding feeds to a format of your choice (PDF, JPG, TXT), once you retrieved the RSS URLs.

Just ideas :smiley:


set rssfolderpath to (((path to library folder from user domain) as Unicode text) & "Mail:Rss:")
tell application "Finder"
	set rssmboxes to every folder of folder (rssfolderpath as alias) whose name ends with ".rssmbox"
end tell

set rssurls to {}
repeat with rssmbox in rssmboxes
	set rssmboxpath to POSIX path of (rssmbox as Unicode text)
	set rssinfopath to (rssmboxpath & "Info")
	set command to "defaults read " & quoted form of rssinfopath & " RSSFeedURLString"
	set command to command as «class utf8»
	set rssurl to (do shell script command)
	if rssurl is not in rssurls then
		set rssurls to rssurls & rssurl
	end if
end repeat

repeat with rssurl in rssurls
	tell application "DEVONagent"
		set rsssource to download markup from rssurl
		set feeditems to get items of feed rsssource
	end tell
end repeat

You can’t access the RSS account directly via AppleScript. But you can of course access it with a rule, and rules can of course move and copy messages.

I begin the rule with an instruction to move the RSS messages I want to work with to another folder, and then call my script with the next instruction. Taking the message out of the RSS account renders it accessible to AS.

Some attributes still require more fussing than they would for a normal incoming message. For example, since RSS messages don’t have attachments as such, it’s necessary to parse the relevant URL out of the message header and then write your own code to handle it.

-Bryan

you also don’t need mail to access rss because you can do it directly in applescript.

set RSSFeed to do shell script "curl -s " & quoted form of "http://www.macscripter.net/extern.php?action=active&type=RSS" without altering line endings
tell application "System Events"
	set RSSFeed to make new XML data with properties {text:RSSFeed, id:0, name:"untitled"}
	set RSSRecords to {}
	repeat with xmlElement in (XML elements of XML element "channel" of XML element "rss" of RSSFeed whose name is "item")
		set end of RSSRecords to {RSSTitle:value of XML element "title" of xmlElement, RSSLink:value of XML element "link" of xmlElement}
	end repeat
end tell

return RSSRecords