2008-07-14 Identi.ca Bot and Adium

http://identi.ca/kensanata

Adium

AppleScript

¹

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

http://identi.ca/kensanata/rss

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! 😄

​#Software ​#Adium ​#Identi.ca ​#Bots ​#AppleScript