The Sun BabelFish Blog
Don't panic !
ruby script to set skype and adium mood message with twitter on osx
Twitter is a great way to learn many little web2.0ish things. I wanted to set the status message on my Skype and Adium clients using my last twitter message. So I found a howto document by Michael Tyson which I adapted a bit to add Skype support and to only post twits that were not replies to someone else - I decide there was just too much loss of context for that to make sense.
#!/usr/bin/env ruby
#
# Update iChat/Adium/Skype status from Twitter
#
# Michael Tyson
# http://michael.tyson.id.au
# Contributor: Henry Story
# Set Twitter username here
Username = 'bblfish'
require 'net/http'
require 'rexml/document'
include REXML
# Download timeline XML and extract latest entry
url = "http://twitter.com/statuses/user_timeline/" + Username + ".atom"
xml_data = Net::HTTP.get_response(URI.parse(url)).body
doc = REXML::Document.new(xml_data)
latest = XPath.match(doc,"//content").detect { |c| not /@/.match(c.text)}
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" +
'if exists process "Skype" then tell application "Skype" to send command "set profile mood_text "'
+ ' & message script name "twitter"'
+ "\n" +
'end tell' + "\n"
IO.popen("osascript", "w") { |f| f.puts(script) }
This can then be added to the unix crontab as explained in Michael's article, and all is good.
What can one learn with this little exercise? Quite a lot:
- Ruby - this is my first Ruby hack
- Atom - twitter uses an atom xml feed to publish its posts
- unix crontab
- AppleScript to send messages to all these silly OSX apps
- vi to edit all of this, but that's not obligatory, you can use less viral ones
- the value of reusing data accross applications
Posted at 02:18PM Dec 12, 2008 [permalink/trackback] by Henry Story in Java | Comments[0]
Note on comments:
- I know the forms below are a little small. We have asked for years for this to be changed, but I don't think it's going to happen soon. In Apple's Safari you can resize the entry box with you mouse. For people using other browsers click on this javascript link, that should allow you to resize your form.
- Comments are moderated, so they will take a little time to appear. Currently moderation means I have to read them personally. Hopefully with OpenId deployment, this will become more automated.
- HTML markup no longer works here, due to some decision made somewhere. Sorry about that.
- If you are having trouble posting, it may be that you need javascript to be enabled. I don't think javascript should be needed for submitting a form, but that's the way it is here.
- Check your comments by using the preview button...
