mime types, update-desktop-database, and Linux Alternatives

What to do if an unexpected program tries to open up a file? You want acrobat reader, but get that horrible kghostviewer.

Understand this:

To find programs, some parts of the desktop framework use the settings given by the "alternatives" framework. Check /etc/alternatives, a big collection of symbolic links.

Here's how you can revise those settings. After I installed seamonkey, I noticed lots of programs like R and Gnome Help were using seamonkey, not firefox. I was stumped a long time. Here's the fix.

$ sudo update-alternatives --config x-www-browser

There are 2 alternatives which provide `x-www-browser'.

Selection Alternative
-----------------------------------------------
1 /usr/bin/firefox-3.0
*+ 2 /usr/bin/seamonkey

Press enter to keep the default[*], or type selection number: 1
Using '/usr/bin/firefox-3.0' to provide 'x-www-browser'.

Other programs do not use alternatives, but rather try to use the xdg-mime framework. A generic command like "xdg-open whatever.pdf" is supposed to open that pdf file in a desired viewer. Use "xdg-mime" functions to view & revise those settings. I've found that system is very tempermental.

Check /usr/share/applications, where programs are supposed to drop "desktop" files. Those are text files with config information. defaults.list is built by update-desktop-database. IF there is a mis-configuration in the preferred app selection through xdg-open, the system.
've tracked down the problem, though, so I can stop kghostview from
being invoked. (more below).

One other thing. The settings can be broken in the user's account. I've found several examples where the .local directory in the user's home account was full of wrong configurations. It kept trying to use gconf-editor to open pdf files. I never found out what the user was doing to make that association re-assert itself, possibly it was some right-clicking in nautilus.

Here was a message I wrote May 5, 2009, that summarized a learning process on the mime type management.

When RPMS install, they often have a post script call to execute
"update-desktop-database" which scans the desktop files under
/usr/share/applications and it builds
/usr/share/applications/mimeinfo.cache.

To my surprise/astonishment, the update-desktop-database function is
completely undocumented, not even a man page or a mention in the
README file from the xdg group that provides it. To my even greater
surprise, there is apparently no way to predict which programs will be
at the front of the list for each mime type. The mimeinfo.cache is
used by programs like nautilus to know what programs are available.
update-desktop-database, for reasons I don't know, places ghostview
first among pdf opener programs.

More and more programs are relying on the "xdg-open" script to select
viewers for files. xdg-open ends up scanning for the desktop framework
in use, in my case Gnome, and then it passes off the pdf file to the
program gnome-open, which is supposed to check for "defaults.list" in
the user's config and in the system at /usr/share/applications. The
mimeinfo.cache file is not supposed to be dominant setting here
because the preferred viewer is supposed to be specified in
defaults.list. We have AdobeReader.desktop specified there.

However, when the config in defaults.list is broken, then xdg-open
(hence gnome-open) don't know what to do, and they consult
mimeinfo.cache and they take the first program listed.

Our config was broken because Adobe was installed incorrectly.
The RPM that installed AdobeReader did not copy AdobeReader.desktop
into /usr/share/applications. As a result, when the user tries to
configure "xdg-open" (via xdg-mime) or use "gnome-open", both try to
use AdobeReader.desktop, and fail, and then they fall back to use the
things in /usr/share/applications/mimeinfo.cache. One can just copy
AdobeReader.desktop from /opt/Adobe/... into /usr/share/applications
to fix this. To be fancier, one can run "xdg-mime install "

To protect my systems from ever using kghostview, I ended up deleting
the Mime line in all of the relevant desktop files in
/usr/share/applicaitons/kde. After that, "update-desktop-database"
can be called and kghostview is never listed as a pdf opener.

About pauljohn

Paul E. Johnson is a Professor of Political Science at the University of Kansas. He is an avid Linux User, an adequate system administrator and C programmer, and humility is one of his greatest strengths.
This entry was posted in Linux. Bookmark the permalink.