Marc Cramdal's blog

Saturday, June 24, 2006

Kopete Scripting

Yes, it is possible to write scripts for Kopete. Kopete has like any other KDE application a nice DCOP interface.

Here are two examples. The scripts are probably not nice but I never really learnt how to make scripts (I usually open a "how to write bash/perl scripts"-webpage while I'm writing a script ;-))

First, an easy one; it output a fortune in Kopete away message:

dcop kopete KopeteIface setAway "`fortune`" false

The next one, using perl. Well, I'm using Gentoo. And I often install some software using emerge. When you run emerge in Konsole, the title bar change to something like "emerge (9 on 43) kde-base/ark-3.0.1". So this script will run in background and every minute (sleep 60), it will cycle through konsole windows and see if one has this kind of title. If true, it outputs it into Kopete away message.

With this, you can watch your compilations when you're not home, without a ssh server, just using your jabber account ;-)

my @konsoleInstances;
my $awayMessage;

while( true )
@konsoleInstances=`dcop | grep konsole`;

foreach $instance (@konsoleInstances)
$instance =~ s/\n//;

$awayMessage=`dcop $instance konsole-mainwindow#1 caption`;

if ($awayMessage =~ /.*emerge.*/)
system("dcop kopete KopeteIface setAway \"$awayMessage\" false");
system("sleep 60");

Using Kicker's Quickbrowser applet, you can quickly access your scripts to renew your fortune when you are bored with the current one :
Image Hosted by

I'm sure there are many other possibilities and I'm sure that some of you already wrote some scripts. Feel free to share !