Marc Cramdal's blog

Sunday, September 03, 2006

Syntax Highlighting update

I always find new wonders in KDE.

Did you know that in Kate configuration, you can update the Syntax Hightlighting. It's easy as pie. Just go in Kate settings, then Editor, then Hightlighting. Once there, you have a download button. A dialog lists then the different rules and automaticaly detects the new ones.

I don't know what I really updated but it's really nice :D

Monday, July 10, 2006

Kopete countdown script

Today is my first holiday day. So I wanted to have a countdown for my away message showing the time left before my holidays and then a nice "Vacances !!!!" (it's holiday in french) message.

To achieve this, I just wrote a little Ruby script this time. It's the first time I write such a big (!) Ruby script and it's very easy with some help.

So this is the result :
Image Hosted by ImageShack.us

And below you can find the script.


#!/usr/bin/ruby

require "time"

###### CHANGE SETTINGS HERE ######
# Can be any valid date time of the type : Wed Apr 09 08:56:04
time0 = String "15:00"

# Message before event occurs, use %% to put the number of hours left
message_before = String "%% heures avant (ip)"

# Message after event occurs. Same use of %% here. It will be a positive number of hours.
message_after = String "Vacances !!!!"

# Update the message every sleep_time seconds
sleep_time = Integer 60
#######

target = Time.parse(time0)

while true
current = Time.new
difference = target - current
hours = (difference.abs / 3600).floor;
minutes = ((difference.abs - hours*3600)/60).floor

# Format the number of hours left
time_left = String(hours) + ":" + sprintf("%02d",minutes)

if difference > 0 # If the event isn't past
`dcop kopete KopeteIface setAway "#{message_before.sub("%%", time_left)}" false`
else
`dcop kopete KopeteIface setAway "#{message_after.sub("%%", time_left)}" false`
break
end

sleep sleep_time;

end

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 ;-)


#!/usr/bin/perl
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");
last;
}
}
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 ImageShack.us


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