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) }

3 thoughts on “Twitter – Adium status syncing ignoring @replies

  1. Thank you for this script! Unfortunately, I don’t get it work. I only get an error message when I try to launch it:
    $ ~/Library/Scripts/sync-status-with-twitter.rb
    345:359: syntax error: A identifier can’t go after this identifier. (-2740)
    Maybe you have an idea how to fix it.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>