On 01/13/2017 09:19 AM, Guenter Milde wrote:
IMV, using xdg-mime query seems the right way but not easy.
Maybe you can open an enhancement ticket.

tl;dr

I'm now having second thoughts about it. I discovered xdg-mime returns incorrect information on my laptop (including naming applications that are no longer installed). As noted here <https://bbs.archlinux.org/viewtopic.php?id=201728>, the problem seems to be that xdg-utils programs focus on ~/.local/share/applications/mimeapps.list and ignore ~/.config/mimeapps.list (which I think is supposed to take precedence).

I don't know why Linux distributions store MIME associations in so many different places, but in any event we apparently can't count on xdg-mime to find the correct associations, and there is no painless way for a user to fix that (at least none that I can find). My laptop has a MIME type editor, but it shows the correct associations (presumably meaning those in ~/.config) and has no provision for tracking down and deleting associations in other obscure locations.

There's an alternative to xdg-open, namely gvfs-open, that seems to do a better job of reading the correct MIME association list. Unfortunately, where xdg-open defaults to Firefox (or whatever the default browser is?) on an unrecognized file type, gvfs-open on my PC tried to open a binary file (proprietary format, no MIME association) with Libre Office, which expectedly did not go well. So I'm hesitant to suggest setting gvfs-open as the default for unknown MIME types.

A possibility is to have the script run 'gvfs-mime --query <MIME type>' and extract the default program from the first line of the return value (or ascertain that no default is set). Given the way xdg-mime blew up in my face, though, I'd like to hear from others before making a formal recommendation. In particular, since both my systems run Linux Mint, I have no idea how ubiquitous gvfs-mime is in other distributions.

Paul

Reply via email to