<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>abednarz.net &#187; ruby</title>
	<atom:link href="http://abednarz.net/wp/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://abednarz.net/wp</link>
	<description>Bed</description>
	<lastBuildDate>Thu, 22 Jul 2010 00:42:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Twitter &#8211; Adium status syncing ignoring @replies</title>
		<link>http://abednarz.net/wp/twitter-adium-status-syncing-ignoring-replies/</link>
		<comments>http://abednarz.net/wp/twitter-adium-status-syncing-ignoring-replies/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 00:41:08 +0000</pubDate>
		<dc:creator>Bed</dc:creator>
				<category><![CDATA[Tech Talk]]></category>
		<category><![CDATA[adium]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[status]]></category>
		<category><![CDATA[sync]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://abednarz.net/wp/?p=331</guid>
		<description><![CDATA[A while ago, I found a nice ruby script that would keep my Adium&#8217;s status synced with my Twitter status. I&#8217;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&#8217;t want these @replies to sync to my [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago, I found a <a title="Michael Tyson's Blog" href="http://michael.tyson.id.au/2008/10/10/keeping-ichat-and-adium-status-in-sync-with-twitter/" target="_blank">nice ruby script</a> that would keep my <a title="Adium" href="http://www.adiumx.com/" target="_blank">Adium&#8217;s</a> status synced with my <a title="Twitter" href="http://twitter.com" target="_blank">Twitter</a> status. I&#8217;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&#8217;t want these @replies to sync to my Adium&#8217;s status. So I&#8217;ve modified the original script to ignore these. This script runs every half hour via launchd.</p>
<pre lang="ruby">
#!/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) }
</pre>
<img src="http://abednarz.net/wp/?ak_action=api_record_view&id=331&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://abednarz.net/wp/twitter-adium-status-syncing-ignoring-replies/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
