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 !


  • Great!
    Do you know how to run the fortune thing in cron? I can't make it work...

    0,5,10,15,20,25,30,35,40,45,50,55 * * * * export DISPLAY=:0.0;dcop kopete KopeteIface setAway "`fortune`" false

    Don't works!

    By Blogger k7k0, at 2:21 AM  

  • First, replace 0,5,..,55 with */5 , that's much shorter :)

    Second, returning to your question, DCOP needs a session ID and user to run from a cronned environment. I tried really hard to make DCOP calls with fcron, but after hours of fiddling I gave up. What you could do is to make a script like

    while [ 1 ]; do
    dcop kopete KopeteIface setAway "`fortune`" false
    sleep 5m

    and make a new link to an application in your Autostart folder, pointing to that script. Then, the DCOP calls will be executed successfully.

    By Blogger Bram, at 11:11 PM  

  • crontab entry:
    # update Kopete's away message
    */5 * * * * /home/goten/bin/newMessage

    # change Kopete's away message
    if [ -n "`ps -A | grep kopete`" ]; then
    /opt/kde/bin/dcop --user goten kopete KopeteIface setAway "`/home/goten/bin/oneliner`" 0
    Note the usage of --user; that's the bit that makes dcop work properly. Also, I have a check to see if Kopete is actually running first ;)

    # strip newlines from a short fortune
    fort=`/usr/games/fortune -s`
    echo ${fort//'\n'//''}

    By Blogger Goten Xiao, at 4:29 PM  

  • you can always check kopete presence
    also by means of
    ~ dcopfind kopete

    this program returns DCOPRef if there is a running app or there is not

    By Blogger Kostya Glazyrin (lorcat), at 11:01 AM  

Post a Comment

<< Home