Return to Snippet

Revision: 29523
at July 31, 2010 05:59 by trepmal


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

# Set Twitter 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) }

Initial URL
http://trepmal.com/scripts/lastfm-ichat-status/

Initial Description

                                

Initial Title
Set iChat status to most recent Last.fm track

Initial Tags
ruby

Initial Language
Ruby