Pete's Linux Advent Calendar 2008
The 11th day
Open a URL in an existing Konqueror Window
Working with KDE? With DCOP it is possible to manipulate KDE Applications.
To open a URL in a Konqueror window from the command line you
could use this script:
#!/bin/bash
getwinid() {
xwininfo | sed -n 's/xwininfo: Window id: 0x\([0-9a-f]*\).*/\1/p'
}
dec2hex() {
printf "%x\n" "$1"
}
openurl() {
local konq="$1" url="$2"
dcop "$konq" "konqueror-mainwindow#1" openURL "$url"
}
getKonquerorWithId() {
local id="$1" konqid
for k in $(dcop | grep "^konqueror-"); do
konqid=$(dcop "$k" "konqueror-mainwindow#1" getWinID)
konqid=$(dec2hex "$konqid")
if [ "$konqid" = "$id" ]; then
echo "$k"
break
fi
done
}
konqid=$( getKonquerorWithId $(getwinid) )
openurl "$konqid" "$1"
If you run this script with the url to open as the only argument
your mouse pointer will form a cross and you only have to click in the window.
It assumes that the program xwininfo(1) is installed.