Monday, January 31, 2011

IRSSI -> Growl

I whipped up a quick hack to give me growl alerts for irssi highlighting. It is pretty horrible, gross, and yucky, but it works well enough for me. I thought I'd share in case people don't care so much about how grotesque this is.


On my server running irssi, I wrote this irssi script:

use Irssi;
use vars qw($VERSION %IRSSI);
$VERSION = "0.01";
%IRSSI = (
authors => "Jason May",
contact => 'jason.a.may@gmail.com',
name => 'alertsfile',
description => 'Send all hilight messages to a file for external apps to process',
license => "Public Domain",
url => "http://irssi.org/",
changed => "2002-03-04T22:47+0100"
);
sub sig_printtext {
my ($dest, $text, $stripped) = @_;
if (($dest->{level} & (MSGLEVEL_HILIGHT|MSGLEVEL_MSGS)) &&
($dest->{level} & MSGLEVEL_NOHILIGHT) == 0) {
$window = Irssi::window_find_name('hilight');
open my $fh, '>>', "$ENV{HOME}/.growl-alerts";
print $fh "$stripped\n";
close $fh;
}
}
Irssi::signal_add('print text', 'sig_printtext');
view raw gistfile1.pl hosted with ❤ by GitHub


On my macbook where I get growl messages I wrote this shell script:

#!/bin/bash
BREWBIN=/Users/jasonmay/.brew/bin
GROWLHOST=$1
(
/usr/bin/ssh "$GROWLHOST" "cat .growl-alerts 2>/dev/null; rm -f .growl-alerts" && echo
) | while read msg
do
# send twice because it doesn't always work the first time... :/
for i in $($BREWBIN/gseq 1 2)
do
echo "$msg" | ( [ "x$msg" == 'x' ] || $BREWBIN/growlnotify "$GROWLHOST" )
done
sleep 10
done
view raw growl-alerts.sh hosted with ❤ by GitHub


...and ran it in cron on my macbook:

* * * * * /path/to/growl-alerts.sh myhost.org