Using KDE’s dcop to list all browser tab URLs and do other handy things

DCOP is KDE’s interprocess communication protocol. Conveniently enough,
developers are pretty good about exposing interfaces to it, and there
is even a shell binding. There are some awfully neat things you can do
with it from a shell interface. This script lists the URLs of all the tabs
in my Konqueror windows:

SESSION=`dcop --list-sessions --user $USER | grep -m 1 DCOP`
dcop --session $SESSION --user $USER | grep konqueror | while read KONQ
do
        dcop --session $SESSION --user $USER $KONQ | grep html-widget | while read WIDGET
        do
                dcop --session $SESSION --user $USER $KONQ "$WIDGET" url
        done
done

This little script will read or set the current Konsole tab’s name:

#!/bin/bash
case $# in
        0) dcop $KONSOLE_DCOP_SESSION sessionName ;;
        *) dcop $KONSOLE_DCOP_SESSION renameSession "$*" ;;
esac

I use that with a script which runs commands from a list based on the tab’s name,
so it’s very easy for me to restart many long-running programs after I log out
and back in. Another nice trick is to tell Konqueror to re-read the bookmarks file,
which is useful if you have something else edit it.

There’s a useful DCOP explorer GUI called “kdcop”. If you just run
that and browse around in your running KDE applications you can probably
come up with lots of other neat ideas!