Twitter – Adium status syncing ignoring @replies

A while ago, I found a nice ruby script that would keep my Adium’s status synced with my Twitter status. I’ve recently started using twitter a bit more, and replying to friends with it. This basically does a tweet with @username at the start of it. I didn’t want these @replies to sync to my Adium’s status. So I’ve modified the original script to ignore these. This script runs every half hour via launchd.

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

# Modified to ignore @reply tweets by Andrew Bednarz
# http://abednarz.net

# Set Twitter username here
Username = 'bed42'

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

# Download timeline XML and extract latest entry
# Skip @reply tweets
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)
index = 1
notreply = false
until notreply
	latest = doc.root.elements['entry/content['+index.to_s()+']']
	message = latest.text.gsub(/^[^:]+:\s*/, '')
	exit if ! message
	if message[0,1]=='@' then
		index = index + 1
	else
		notreply = true
	end
end

# 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) }
Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

One Response to “Twitter – Adium status syncing ignoring @replies”

  • Andy Hugelier says:

    This works great! Thanks so much!

  • Leave a Reply:

    Name (required):
    Mail (will not be published) (required):
    Website:
    Comment (required):
    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>