Setting the default browser

How to setup terminal mime association so that xdg-open URL opens the right browser profile

Published: Thursday, Jul 1, 2021 Last modified: Thursday, Nov 14, 2024

Update: I’ve written my own x-www-browser handler and x-www-browser.desktop

$ xdg-mime query default x-scheme-handler/http
firefox.desktop
$ xdg-settings get default-web-browser
firefox.desktop
$ xdg-open https://example.com

Will open Firefox of course

You can create your own .desktop files like so:

$ cat ~/.local/share/applications/firefox-personal.desktop
[Desktop Entry]
Version=1.0
Name=Firefox
GenericName=Web Browser
Exec=/usr/lib/firefox/firefox -P hendry %u
Icon=firefox
Terminal=false
X-MultipleArgs=false
Type=Application
MimeType=text/html;text/xml;application/xhtml+xml;x-scheme-handler/http;x-scheme-handler/https;application/x-xpinstall;
StartupNotify=true
StartupWMClass=firefox
Categories=Network;WebBrowser;

My profile name is hendry, though it’s not clear this is the name from Firefox’s about:support. You have to parse this out of Profile Directory’s SALT. In Chrome you can figure out the Profile directory from chrome://version/.

The .desktop format linted like so desktop-file-validate ~/.local/share/applications/firefox-personal.desktop

Thanks to https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s07.html I now know the difference between:

You might also need to run update-desktop-database ~/.local/share/applications

Set it like so:

$ xdg-settings set default-web-browser firefox-personal.desktop

Ultimately your system’s application associations are stored in ~/.config/mimeapps.list

$ xdg-settings set default-web-browser firefox-personal.desktop
$ XDG_UTILS_DEBUG_LEVEL=2 xdg-mime query default text/html
Checking /home/hendry/.config/mimeapps.list
firefox-personal.desktop

Bizarrely there doesn’t seem to be a way to easily track down the location of firefox-personal.desktop.

google-chrome

After reporting a bug, I now know how to switch profiles, e.g.

More info