Where does firefox get the “default” applications for opening files from?
A link to a “similar question” (xdg-open default applications behavior – not obviously related, but some experimentation showed that the behaviour is indeed equivalent to the one of xdg-open
) led me deeper down the rabbit hole. While Firefox does not rely on, or inherit rules from, xdg-open
, it uses the MIME specification files just as xdg-open
does.
On a user basis, the MIME opening behaviour is configured by the specification file ~/.local/share/applications/mimeapps.list
.
For me, this file contains just a few reasonable protocols and HTML (and similar) files connected to userapp-Firefox-??????.desktop
, but you could easily add a line like
application/pdf=evince.desktop
to solve that problem on a per-user basis. If the file does not exist yet, make sure to add a section header, such as
[Default Applications]
application/pdf=evince.desktop
Deeper down, the mime types are defined in /usr/local/share/applications/mimeinfo.cache
(this may be /usr/share/…
if you are not on a FreeBSD system), which does list application/pdf=inkscape.desktop;evince.desktop;
. Both evince.desktop
and inkscape.desktop
in that folder contain MimeType=[…]application/pdf;[…]
.
The mimeinfo.cache
is automatically generated from the mime types listed in the .desktop
files without any well-defined order, so you will have to either remove the PDF mime type from Inkscape and regenerate the cache using update-mime-database
, or generate a mimeapps.list (either globally in /usr/local/share/applications/
, or for your user in ~/.local/share/applications/mimeapps.list
).
In Firefox 38.8.0 ESR, under Debian Lenny with GNOME 2, I discovered that the application associated via XDG (described in the answer by the OP) is used only when opening a downloaded file from Downloads in the Library.
And even there, the implementation gives results inconsistent with xdg-open
as it ignores GNOME-specific paths (in my case /usr/share/gnome/applications/defaults.list
, which is a symlink to /etc/gnome-vfs-2.0/defaults.list
). I had to specify application/pdf=evince.desktop
in my ~/.local/share/applications/defaults.list
. (Note that defaults.list
was merged in mimeapps.list
in more recent versions of XDG.)
Instead of XDG, metamail capabilities (mailcap) are used to resolve the associated application for the following use cases:
- opening downloaded file from the download panel (displayed after pressing the download button in toolbar)
- default application in the drop-down in file download dialog
- default application in the drop-down in Preferences → Applications (
about:preferences#applications
)
The preference in about:preferences#applications
is used when navigating to an URL with that content type, unless download is forced.
Mailcap is a mechanism older than XDG and has its roots in e-mail, where MIME comes from, too. The run-mailcap
utility is analogical to xdg-open
. Its configuration comprises three files (in decreasing precedence):
~/.mailcap
— user entries/etc/mailcap.order
— system-wide entries ordering specification/etc/mailcap
— system-wide entries (same format as user entries)
Together they produce a list of one-line entries that specify the application to be used for any given MIME type. The entries are matched top-down, so what comes first takes precedence.
To make a system-wide change of entries precedence, you need to edit /etc/mailcap.order
and run update-mime
.
To override some of the entries or specify your own, system-wide, you need to edit the top section (meant for manually created entries) of /etc/mailcap
and run update-mime
. See the comments in the top section.
For user entries and overrides, use ~/.mailcap
. The changes take effect immediately. No ~/.mailcap.order
exists; if you want to change entries precedence, reorder them physically (if they are in ~/.mailcap
), or override them with the preferred version (if they are in /etc/mailcap
).
See man update-mime
, man mailcap
and man mailcap.order
.
Note that some applications use generic utilities (such as x-www-browser
or pager
) instead of detection of the preferred application. You may need to use update-alternatives
or a similar mechanism for choosing the preferred implementation of a generic utility in your distro. Or, to override a system-wide preferred alternative for a specific user, set environment variables such as EDITOR
(or VISUAL
), PAGER
and BROWSER
. They are supported by sensible-browser
and other, often more specific tools (e.g. git commit
uses EDITOR
and VISUAL
).