If you are using a Desktop Environment, managing default applications is easy. There should be a dedicated section in settings where you can configure default applications like Web Browser:
If you want a fine-grained control, you can open a file manager, right click a file, select Open With…, then choose the application you want and make it the default.
But how do you manage default applications in a window manager, where all tools mentioned above may not exist in the system?
MIME Applications Associations
Association between MIME types and applications explains how things work under the hood. When we configure default applications in GUI, we are actually modifying
$XDG_CONFIG_HOME/mimeapps.list (mostly). We can modify it manually, or use tools provided by xdg-utils:
# set the default web browser to firefox.desktop xdg-settings set default-web-browser firefox.desktop # set the default mailto URL scheme handler to be thunderbird.desktop xdg-settings set default-url-scheme-handler mailto thunderbird.desktop # let imv-folder.desktop open .png files xdg-mime default imv-folder.desktop image/png
That’s basically it. If you need to set the default image viewer, you may want to find all MIME types for images you may encounter, then set them respectively1. Knowing that there are so many types to add to
mineapps.list, you may want to write
image/*, but wildcard in
mineapps.list is not supported2.
At this point, two roads diverge:
- Use an utility to simplify the process.
- Ditch xdg-utils, use a better alternative.
Select Default Application is a very simple tool that does the job. I quote from the README.md:
Basically it just loads all installed applications by reading their .desktop files, reads the MimeType fields to see what it supports, and updates ~/.config/mimeapps.list with what the user wants.
handlr is a better xdg-utils with a more user-friendly interface and more features. For example, it supports wildcard, so we can write
mineapps.list like this:
$ handlr add image/'*' imv-folder.desktop $ handlr add text/'*' nvim.desktop $ handlr add video/'*' mpv.desktop $ handlr list ┌─────────┬────────────────────┐ │ image/* │ imv-folder.desktop │ │ text/* │ nvim.desktop │ │ video/* │ mpv.desktop │ └─────────┴────────────────────┘ $ cat ~/.config/mimeapps.list [Added Associations] [Default Applications] image/*=imv-folder.desktop; text/*=nvim.desktop; video/*=mpv.desktop;
And there is more: don’t remember the MIME type for a .mp3 file? It doesn’t matter! With
handlr, we can do this:
# handlr knows that a mp3 extension belongs to audio/mpeg $ handlr add .mp3 mpv.desktop $ handlr list ┌────────────┬────────────────────┐ │ audio/mpeg │ mpv.desktop │ │ image/* │ imv-folder.desktop │ │ text/* │ nvim.desktop │ │ video/* │ mpv.desktop │ └────────────┴────────────────────┘ $ cat ~/.config/mimeapps.list [Added Associations] [Default Applications] audio/mpeg=mpv.desktop; image/*=imv-folder.desktop; text/*=nvim.desktop; video/*=mpv.desktop;