What a great idea!
I immediately set this up and it works great on my system. Adapt the following script to your needs (you'll need superuser rights to install the script!):
#!/bin/bash
# looking for Firefox instances
pgrep -l '^firefox-bin$' > /dev/null
if [ $? -eq 0 ]; then
echo
echo " Opening link in Firefox..."
echo
/usr/bin/firefox "$1"
exit
fi
# looking for Konqueror instances
pgrep -l '^konqueror$' > /dev/null
if [ $? -eq 0 ]; then
echo
echo " Opening link in Konqueror..."
qdbus `qdbus | grep -m1 konqueror` /konqueror/MainWindow_1 org.kde.Konqueror.MainWindow.newTab "$1" False
exit
fi
# no browser instances found, so open default browser
echo
echo -n " No open browser found. "
if [ -z "$1" ]; then
echo "Opening new Firefox instance..."
echo
/usr/bin/firefox &
exit
else
echo "Opening link in new Firefox instance..."
echo
/usr/bin/firefox "$1" &
exit
fi
The unmodified script will try to open a link (specified in $1) using Firefox. If no instance of Firefox is found, it will try to reuse Konqueror. Finally, if no instance of Konqueror is found, the script will open a new instance of Firefox.
When you're done, save the script at /usr/local/bin/reuse_open_browser
and run the following commands:
sudo chmod +x /usr/local/bin/reuse_open_browser
sudo chown root:root /usr/local/bin/reuse_open_browser
sudo update-alternatives --install /usr/bin/x-www-browser x-www-browser /usr/local/bin/reuse_open_browser 100
Then select the script as default by running
sudo update-alternatives --config x-www-browser
Enjoy! :)