12

By default, the Firefox (33.0) on my FreeBSD 11.0-CURRENT has the default application for opening PDF files set to Inkscape. Firefox does remember my previous choice, evince, in the “What should Firefox do with this file?” dialog, so until recently I was just confused where this configuration came from, but mostly ignored it because it did barely concern me.

I have however recently started using Zotero as my literature database. Zotero runs as a firefox plugin, and ignores the choices made in my Firefox preferences to open PDF files with evince or ask me what to do with them, and just opens them using Inkscape. This made me try to follow up on this particular configuration item of Firefox, but I could not find where that default is set.

I could not find the string Inkscape (or inkscape) in any Firefox-related file in my home directory.

14

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).

  • On my ancient Debian Linux, update-mime-database does something different, I needed update-desktop-database ~/.local/share/applications. – Palec May 13 '17 at 9:52
  • Also, xdg-open file.pdf opens Evince (as does Nautilus), while Firefox opens xpdf. Using find ~/.local/share/applications/ /usr/share/applications/ -type f -exec grep -i pdf '{}' + I found that PDF is mentioned nowhere in user configuration, only in /usr/share/applications/mimeinfo.cache and respective *.desktop files. The line in mimeinfo.cache is application/pdf=xpdf.desktop;evince.desktop;xournal.desktop;. I guess FF takes the first item. But how does xdg-open know I want Evince? – Palec May 13 '17 at 9:59
  • 1
    Using strace, I discovered that xdg-open calls gnome-open and gnome-open reads /usr/share/gnome/applications/defaults.list, which is a symlink to /etc/gnome-vfs-2.0/defaults.list, which specifies application/pdf=evince.desktop. Obviously, vanilla FF lacks GNOME integration and thus ignores this preference. – Palec May 13 '17 at 10:30
6

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).

  • 1
    This answer ist still valid in Firefox Quantum (64.0). However, mailcap performs better than actual firefox, so you cann't fully rely on run-mailcap --debug --norun. I have an entry like this: application/pdf; sh -c "MEANINGFUL_VAR=preset /usr/bin/evince '%s'". Firefox then invokes sh downloaded_file.pdf. On my console I then see, amongst others /tmp/mozilla_user/downloaded_file.pdf: line 3: 5: command not found etc. This behaviour will remain forever, unless someone fixes this. See Mozilla Bugzilla. – u_Ltd. Oct 5 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.