
Script Hacks with DCOP #39
Chapter 5, KDE Desktop
|
129
HACK
Notice how you need to specify the process number of the application
within the application name (your process number might be different from
mine). This is so you can probe the correct Konqueror process and open a
new browser window.
Write a DCOP Shell Script
The true power of DCOP comes into its own when you start writing shell
scripts. As an example, imagine that numerous applications are in use across
all your virtual desktops. Things are getting a little messy on these desktops
and you want to tidy up. You can solve this problem by writing a little script
that switches to each desktop and runs the
cascadeDesktop interface, which
organizes the windows in a cascaded order.
To create this script, create a new file called cascade.sh and add the follow-
ing code:
#!/bin/bash
for i in seq 1 5:
do
dcop kwin KWinInterface setCurrentDesktop $i
dcop kwin KWinInterface cascadeDesktop
done
This code creates a bash for loop that loops four times (for the number of
desktops). Inside the loop, it sets the current desktop to that of the loop
number, and then it issues the
cascadeDesktop interface command.
To run the script, you need to turn on the execute bit on the file:
foo@bar:~$ chmod a+x cascade.sh
Then you can run the script with:
foo@bar:~$ ./cascade.sh
As another example, say you want to receive an email when your friend
Nick logs on to your instant