Diary SiteMap RecentChanges About Contact Calendar

Search:

Matching Pages:

Journal

2008-09-13 Adium, Twitter, and Identica

My current setup:

  1. Send my current status to the Identica bot using Adium. I have Adium configured to run an Applescript whenever I do that.
  2. The script waits a few seconds and determines the current status by checking the Identica RSS feed.
  3. Then the script posts the status to Twitter using the Twitter API.
  4. Then the script tells the Adium application to use the status.

Applescript for Mac OS 10.4 / Adium 1.3.1:

delay 5
set myStatus to do shell script "~/bin/identica --nick kensanata"
do shell script "~/bin/twitter " & quoted form of myStatus
tell application "Adium"
	repeat with theAccount in accounts
		go online theAccount with message myStatus
	end repeat
end tell

The script that fetches my current status:

#!/usr/bin/perl
use XML::RSS;
use LWP::UserAgent;
use Getopt::Long;

my $verbose = undef;

sub get_feed {
  my $url = shift;
  my $ua = LWP::UserAgent->new;
  my $response = $ua->get($url);
  print $response->code, ' ', $response->message, "\n" if $verbose;
  return $response->content if $response->is_success;
  die $response->code, ' ', $response->message, "\n";
}

sub get_status {
  my $url = shift;
  my $rss = new XML::RSS;
  my $string = get_feed($url);
  print $string if $verbose;
  $rss->parse($string);
  return $rss->{items}->[0]->{title};
}

sub main {
  my $nick = '';
  GetOptions('nick=s' => \$nick,
	     'verbose' => \$verbose);
  my $url = "http://identi.ca/$nick/rss";
  warn "No nick specified.\n" unless $nick;
  binmode STDOUT, ':utf8'; # I assume?
  my $status = get_status($url) . "\n";
  $status =~ s/^$nick: //;
  print $status;
}

main();

The twitter status posting script:

#!/bin/sh
if test -z "$*"; then
    echo "Status is missing" 1>&2
    exit 1;
fi
CODE=`curl --silent --output /dev/null --write "%{http_code}" \
    --user kensanata@gmail.com:mypassword --data status="$*" \
    http://twitter.com/statuses/update.xml`
if test "$CODE" != "200"; then
    echo "$CODE: Posting failed" 1>&2
    exit 1;
fi

Tags: RSS RSS RSS RSS RSS RSS

Add Comment

2008-07-14 Identi.ca Bot and Adium

Goal: Send a message to update@identi.ca via my GTalk account, which posts it to http://identi.ca/kensanata. At the same time, Adium should refresh my status from Identi.ca. In order to do that, I tell Adium to run a little AppleScript whenever I send a message to update@identi.ca which in turn runs a little Perl script [1], which fetches my RSS feed from Identi.ca and extracts the latest status and uses it.

Thus, we need three pieces:

  1. A Perl script to extract the current status from http://identi.ca/kensanata/rss
  2. An AppleScript to run the Perl script and set the Adium status
  3. Configure Adium to run the AppleScript whenever I send a message to update@identi.ca

Perl Script

I call it identica and have it stored in my ~/bin folder. Make sure this directory is in your PATH and that it is executable (chmod +x identica). Test it by running identica --nick kensanata and you should get my current status.

Note the dependencies. You might have to install those Perl modules. Sorry about that.

#!/usr/bin/perl
use XML::RSS;
use LWP::UserAgent;
use Getopt::Long;

my $verbose = undef;

sub get_feed {
  my $url = shift;
  my $ua = LWP::UserAgent->new;
  my $response = $ua->get($url);
  print $response->code, ' ', $response->message, "\n" if $verbose;
  return $response->content if $response->is_success;
  die $response->code, ' ', $response->message, "\n";
}

sub get_status {
  my $url = shift;
  my $rss = new XML::RSS;
  my $string = get_feed($url);
  print $string if $verbose;
  $rss->parse($string);
  return $rss->{items}->[0]->{title};
}

sub main {
  my $nick = '';
  GetOptions('nick=s' => \$nick,
	     'verbose' => \$verbose);
  my $url = "http://identi.ca/$nick/rss";
  warn "No nick specified.\n" unless $nick;
  binmode STDOUT, ':utf8'; # I assume?
  my $status = get_status($url) . "\n";
  $status =~ s/^$nick: //;
  print $status;
}

main();

AppleScript

Open the Script Editor and create the following script, replacing “kensanata” with your own nick. Make sure you call up the library list using ⇧⌘L and add Adium.

I called the script “Identica to Adium” and also saved it as a script in my ~/bin folder.

Unfortunately, if you are using Mac OS 10.3 you are stuck with Adium 1.0.

Adium 1.0 for Mac OS 10.3

set myStatus to do shell script "~/bin/identica --nick kensanata"
tell application "Adium"
	set my status message to myStatus
end tell

Adium 1.2 for Mac OS 10.4

set myStatus to do shell script "~/bin/identica --nick kensanata"
tell application "Adium"
	tell application "Adium" to go online with message myStatus
end tell

Configure Adium

In your list of contacts, edit the info for update@identi.ca, switch to the events tab, and find the entry that says “message sent” or something similar (my own Adium says “Nachricht gesendet”). Edit it and specify that you want to run an AppleScript and pick the “Identica to Adium” we just created.

Test

Send the message “Testing…” to update@identi.ca. After a second your Adium status should change accordingly.

Hurray! :)

Tags:

Add Comment