Set your ichat status to your most recent last.fm play

I can’t really take credit for this, it’s just a slightly modified version of what’s available from this guy: http://atastypixel.com/blog/keeping-ichat-and-adium-status-in-sync-with-twitter/ You can use the instructions provided on that site to get this setup.

I increased the frequency and had to remove the tilde (~) from the path in the cronjob.

#!/usr/bin/env ruby
#
# Update iChat/Adium status from last.fm
#
# Michael Tyson
# http://michael.tyson.id.au

# Set last.fm username here
Username = 'yourUsername'

require 'net/http'
require 'rexml/document'

# Download timeline XML and extract latest entry
url = "http://ws.audioscrobbler.com/1.0/user/" + Username + "/recenttracks.rss"
xml_data = Net::HTTP.get_response(URI.parse(url)).body
doc    = REXML::Document.new(xml_data)
latest = doc.root.elements['channel/item/title']
message = '♫ ' + latest.text.gsub(/^[^:]+:s*/, '')

exit if ! message

# Apply to status
script = 'set message to "' + message.gsub(/"/, '\"') + ""n" +
         'tell application "System Events"' + "n" +
         'if exists process "iChat" then tell application "iChat" to set the status message to message' + "n" +
         'if exists process "Adium" then tell application "Adium" to set status message of every account to message' + "n" +
         'end tell' + "n"

IO.popen("osascript", "w") { |f| f.puts(script) }

One thought on “Set your ichat status to your most recent last.fm play”

  1. I’m getting this error message when executing the script via terminal:

    “228:242: syntax error: A identifier can’t go after this identifier. (-2740)”
    Any ideas?

    Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: