Updating Twitter via iChat or AIM status message
Update: Here is a Cocoa version that is easier to use!
May did a good job selling us on Twitter, so now you can see my twittr status in the sidebar.. I wished that changing my Twitter status was as easy as changing my iChat status, so I hacked up this bit of perl that will update it when your iChat status changes. It runs every five minutes via launchd, and uses the newly-announced Twitter API.
PERL:
-
#!/usr/bin/perl
-
use strict;
-
use warnings;
-
use URI::Escape;
-
-
my $user = ‘user@example.com’;
-
my $pass = ‘pin’;
-
-
my $isAvailable = `osascript -e ‘tell application "iChat" to status’`;
-
chomp $isAvailable;
-
-
-
my $status = `osascript -e ‘tell application "iChat" to status message’`;
-
chomp $status;
-
-
if (” eq $status) {
-
$status = ‘lazy’;
-
}
-
-
my $savedStatusFile = ’savedStatus.txt’;
-
-
my $savedStatus = ”;
-
if (-e $savedStatusFile) {
-
$savedStatus = `cat $savedStatusFile`;
-
}
-
-
if ($status ne $savedStatus) {
-
#status changed, update twitter
-
-
my $encStatus = ’status=’ . uri_escape($status, “^A-Za-z0-9″);
-
-
-
print FILE $status;
-
close FILE;
-
}
You can get launchd to run the script every five minutes by creating a file called ~/Library/LaunchAgents/net.tikirobot.status.plist that looks like this:
XML:
-
<?xml version=“1.0″ encoding=“UTF-8″?>
-
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "https://www.apple.
-
com/DTDs/PropertyList-1.0.dtd">
-
<plist version=“1.0″>
-
<dict>
-
<key>Label</key>
-
<string>net.tikirobot.status</string>
-
<key>ProgramArguments</key>
-
<array>
-
<string>/Users/user/status.pl</string>
-
</array>
-
<key>StartInterval</key>
-
<integer>300</integer>
-
</dict>
-
</plist>
And then load the job using:
launchctl load ~/Library/LaunchAgents/net.tikirobot.status.plist
Update: The script now uses URI::URL and POST. Fixed a typo.
Update2: Now uses URI::Escape

Why oh why does our theme make source code look like shit?
I dunno ... I changed it to use the "pre" tag and it was even worse. We need to go find someones source code CSS and lift it .....
How can WordPress/our stupid theme fuck up even the pre tag?
And you know what else? When you try to edit the post, WordPress translates all ampersand-l-t-semicolons back into angle brackets, and you have to manually change them back.
To make the problem even worse, Apple's plist format is stupidly verbose. I'm only setting two parameters. The xml should be as simple as this:
<cron>
<path>/full/path/blah.pl</path>
<interval>300</interval>
</cron>
OK, the ig:syntax hiliter is now installed, and things look much better. I found it on this list of wordpress syntax highlighters.
just testing this thing out :)
TESTING :)
This looks awesome and I want to give it a try, but permissions are flaked. I made status.pl 777. but I still get this in the console:
Oct 11 02:43:14 adamnan launchd[2485]: net.tikirobot.status: execvp("/Users/Dydimustk/status.pl", ...): Permission denied
Oct 11 02:43:14 adamnan launchd[2482]: net.tikirobot.status: execve(): Permission denied
dydimustk, does status.pl work for you if you run it from the command line? Stupid launchd...
Sorry that I didn't get back to you till now. I did get it to work with a little messing around in launchd. But I wanted to mention, that I want to try and get this to work in reverse now as well. So that iChat will grab its status from twitter. If I get it working, I'll post it here.
I want this to work the other way around... when I change my Twitter info, I want *that* to become my iChat status message.
Can that be done?
Sure.. you will have to change the script a bit, but it's not too hard.
If you don't want to mess with it yourself, I might be able to do it in a few days when I get some time...
Thanks for posting something like this. Unfortunately, I can't get it to work. I'm getting something like this in the Terminal:
chrischris:~ chris$ launchctl load ~/Library/LaunchAgents/net.twitter.status.plist
launchctl: propertyList is NULL
launchctl: no plist was returned for: /Users/chris/Library/LaunchAgents/net.twitter.status.plist
launchctl: no plist was returned for: /Users/chris/Library/LaunchAgents/net.twitter.status.plist
nothing found to load
Don't know what I'm doing wrong. Please help!
OK, I made a Cocoa version that is much easier to use. You can get it here
[...] while back I posted a perl script that would update your Twitter status whenever you changed your iChat status message. [...]
[...] Updating Twitter via iChat or AIM status message [...]