Posted By

trepmal on 07/31/10


Tagged

ruby ichat lastfm


Versions (?)

Set iChat status to most recent Last.fm track


 / Published in: Ruby
 

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

  1. #!/usr/bin/env ruby
  2. #
  3. # Update iChat/Adium status from Twitter
  4. #
  5. # Michael Tyson
  6. # http://michael.tyson.id.au
  7.  
  8. # Set Twitter username here
  9. Username = 'yourUsername'
  10.  
  11. require 'net/http'
  12. require 'rexml/document'
  13.  
  14. # Download timeline XML and extract latest entry
  15. url = "http://ws.audioscrobbler.com/1.0/user/" + Username + "/recenttracks.rss"
  16. xml_data = Net::HTTP.get_response(URI.parse(url)).body
  17. doc = REXML::Document.new(xml_data)
  18. latest = doc.root.elements['channel/item/title']
  19. message = '♫ ' + latest.text.gsub(/^[^:]+:\s*/, '')
  20.  
  21. exit if ! message
  22.  
  23. # Apply to status
  24. script = 'set message to "' + message.gsub(/"/, '\\"') + "\"\n" +
  25. 'tell application "System Events"' + "\n" +
  26. 'if exists process "iChat" then tell application "iChat" to set the status message to message' + "\n" +
  27. 'if exists process "Adium" then tell application "Adium" to set status message of every account to message' + "\n" +
  28. 'end tell' + "\n"
  29.  
  30. IO.popen("osascript", "w") { |f| f.puts(script) }

Report this snippet  

You need to login to post a comment.