Open Links in Your Linux Distro’s Current Browser Instead of the Default

This post is inspired by this lifehacker post which shows how to open links in your Mac’s current browser instead of the default. I also use multiple browsers and face the same annoyance. Hence I decided to create a similar solution for linux too.

1) Opens the currently active browser even if its not the default browser.
2) If more than 2 browsers are active, opens the default browser if its running, otherwise it opens the longest running browser.
3) If no browser is active, opens the default browser.

To make sure the solution works, you will have to set the default x-www-browser for your distribution using the update-alternatives command. Use the command below.

sudo update-alternatives --config x-www-browser

Enter the number corresponding to the browser you want as your default browser.

Once that is done, its time to incorporate the script. I have included all the popular browsers included in most linux distributions, but its fairly easy to add any unsupported browser to this script. Copy the script at the end of this post and save it to a file preferably in the bin directory inside your home directory (For eg. /home/pratik/bin/ Now, lets make the script executable.

chmod u+x

Its time to set your window manager’s default browser setting. I am including the screenshots for kde.

Open “Default Applications” through the Run Command Interface (Alt + F2) or the Application Launcher (Alt + F1).

Set that was created above as your default browser.

For gnome, the default application should be set to something like: %s

Thats it, now open a link from Tweetdeck or any other application and it should open the way you want it to.

browsers=( firefox chromium-browse opera epiphany galeon midori konqueror rekonq dillo )
for browser in ${browsers[*]}
  pgrep $browser >> /tmp/log
  if [ "0" == "$active" ]; then
  let browserstatus+=$active
if [ "$browserstatus" == "$noofbrowsers" ]; then  #no browsers actives, open the default browser
  x-www-browser $1 &
elif (( $browserstatus < $((noofbrowsers-1)) )); then #more than two browsers are open, open the default browser
#more than two browsers open, open the default if its active, or the longest running browser
    defaultbrowser=`update-alternatives --query x-www-browser | grep Value | tr '/' '\n' | tail -1`
    if [ "$defaultbrowser" == "chromium-browser" ]; then
        defaultbrowser="chromium-browse"    #hack for chromium
    pgrep $defaultbrowser
    if [ "0" == "$?" ]; then
        x-www-browser $1 &
        command="ps O stime"
        for browser in ${browsers[*]}
            command="$command -C ${browser}"
    activebrowser=`$command | head -2 | tail -1 | tr ' ' '\n' | tail -1 | tr '/' '\n' | tail -1`
        $activebrowser $1 &

else #open the active browser
  if [ "$activebrowser" == "chromium-browse" ]; then
        activebrowser="chromium-browser"    #hack for chromium
  $activebrowser $1 &

Let me know if this solution worked for you.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.