detfalskested

Launch different browsers, based on the URL

9. maj 2014 af Mikkel Munch Mortensen

In my onging struggle as a tin foil hat to not be tracked by Evil Corp™ and it's government associates, I've started blocking cookies from anything Google in my primary browser.

I still use Google search once in while. It works perfectly fine without cookies (and it may even help you pop your filter bubble).

But I ran into some problems with all the Google Apps – Calendar, Docs, etc. – which I use daily at work. I started using these in a separate browser, Chromium, but whenever I clicked a link – e.g. in an e-mail – pointing to a shared document or a calendar event, it opened in my primary browser, and I had to copy/paste the link to Chromium. That was kinda annoying.

Today I created a small bash script that, based on the URL, launches the right browser:

#!/bin/bash

URL=$1

GOOGLE="^https?://.+\.google\..+/"
GSEARCH="^https?://.+\.google\..+/search"

if [[ $URL =~ $GOOGLE ]] && [[ ! $URL =~ $GSEARCH ]]; then
    chromium-browser $URL
else
    firefox $URL
fi

Only thing I needed was to register this script as the default browser in Ubuntu. After searching the interwebz for a while, I found a solution:

You need to create a custom-browser.desktop file in ~/.local/share/applications/ that resembles this:

[Desktop Entry]
Version=1.0
Name=Autobrowser, detect by URL
GenericName=Web Browser
Exec=/path/to/the/browser-script.sh %u
Terminal=false
X-MultipleArgs=false
Type=Application
Icon=firefox
Categories=GNOME;GTK;Network;WebBrowser;
MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/rss+xml;application/rdf+xml;image/gif;image/jpeg;image/png;x-scheme-handler/http;x-scheme-handler/https;x-scheme-handler/ftp;x-scheme-handler/chrome;video/webm;application/x-xpinstall;

Then make sure the new application is registered by running update-desktop-database ~/.local/share/applications and voilà: It's possible to select this as the default browser in the Default Applications settings. Screenshot of the default apps selection in Ubuntu

Skriv kommentar

  • Brug Textile hvis du vil lave funky ting i din kommentar.