Setting Rhapsody Now Playing to the Adium Status

March 28th, 2007 by Josh

I’m not really much of a hacker when it comes down to it but I’ve been fooling around with a lot more tools and possibilities since I got this 15″ MacBook Pro at work. I run Parallels Desktop and Windows XP most of the day so I have access to Visual Studio development tools, SQL Server, and of course, the Rhapsody client.

On the Mac side I use Adium for chat and I love the Now Playing status script that shows the current iTunes track in your status. But since I don’t use iTunes most of the time I was out of luck. Well today I managed to whip up an AppleScript that puts the currently playing Rhapsody track (sort of) in the Adium status.

If you want the whole script, it’s after the jump.

Bear in mind this is the first AppleScript I’ve ever written so I’m sure it’s got issues (for example, deleting the temp file at the end doesn’t work). It’s also reading the now playing data from the user track history rss feed on rhapsody.com which never seems in sync. As for running the script regularly, I’m using the Scheduler in Entourage to make it run every five minutes. It would probably be better to use a cron job.

Note: WordPress is escaping all the characters so you can’t just copy and paste. Here’s a link to the script.



tell application "System Events"
	if (count (every process whose displayed name is "RealNetworks Rhapsody.app")) > 0 and (count (every process whose displayed name is "Adium.app")) > 0 then
		my SetMessage()
	else
		-- my tellAdiumStatus("")
	end if
end tell

on SetMessage()
	set locDir to "/Users/xxxxx/"  -- replace with your temp directory
	set locFile to "rhapsodyTracks.xml"
	set xmlUrl to ("http://feeds.rhapsody.com/user-track-history.rss?rhapUserId=xxxxxxxx&userName=I") -- replace with URL to your track history feed

	-- get RSS
	do shell script "curl \"" & xmlUrl & "\" -o \"" & locDir & locFile & "\" "

	set xmlFile to (locDir & locFile)

	-- get xml data from xml file
	set xmlData to getData(xmlFile)

	tell application "System Events"
		set root to XML element 1 of xmlData
		set channel to XML element 1 of root
		set myitem to XML element "item" of channel

		set artist to value of XML element "rhap:artist" of myitem
		set album to value of XML element "rhap:album" of myitem
		set albumid to value of XML element "rhap:album-rcid" of myitem
		set currtrack to value of XML element "rhap:track" of myitem
		set link to value of XML element "link" of myitem

		-- get album link
		set newlink to "http://www.rhapsody.com/album?albumId=" & albumid

		set statusMessage to "currently hearing: " & artist & " - " & currtrack & " (listen)"

		my tellAdiumStatus(statusMessage)

	end tell

	tell application "Finder"
		--try
		set fileName to locDir & locFile
		if exists file fileName then
			display dialog "exists"
			delete file fileName
		end if
		-- end try
	end tell
	return statusMessage
end SetMessage

on tellAdiumStatus(statusMessage)
	-- display dialog statusMessage
	tell application "Adium"
		set my status message to statusMessage
	end tell
end tellAdiumStatus

on getData(theFile)
	set theXmlfile to (POSIX file theFile) as Unicode text
	tell application "System Events" to return (contents of XML file theXmlfile)
end getData


Leave a Reply