October 24, 2003

Mozilla and Klipper

Klipper is a clipboard tool that is provided with the KDE Desktop (at least on SuSE Linux, my distribution). It not only holds onto the last n clipboard contents, but also parses the current content. If the content matches a known pattern, Klipper pops up a menu that allows you to execute a command on the selected text.

Klipper comes configured with a command that proposes starting the Konqueror web browser when it encounters an HTTP URL. The command uses the KDE framework to locate a running copy of Konqueror and instructs it to open the page; if Konqueror isn't running, the command starts a fresh copy.

I like to use Mozilla, and wanted the same CPU-saving capability. So after looking around, I found the -remote option for Mozilla, and created the following script, that I added to the Klipper configuration as another action when a URL is encountered.

(mozilla -remote "ping()" && \
mozilla -remote "openUrl($1,new-tab)") || \
mozilla $1 &
Klipper is configured to call this script with the URL as the first parameter, as in
/home/user/scripts/openMozilla %s
The first line “pings” Mozilla to see if it is running already; if so, the second line is executed to tell the running program to open the URL in a new tab. If Mozilla isn't running yet, the third line starts it, pointing to the URL.

I could have included this script as a single line of code in the Klipper configuration, except that Klipper passes the URL as

'http://www.w3.org/'
and Mozilla gets upset by the extra single quotes. Posted by ronlusk at October 24, 2003 12:02 PM
Comments