How does xdg-open do its work

According to the man page, xdg-open will open a file using the application the user has configured. But how is that application actually determined? I can see no config files associated with xdg-utils, so where are my settings stored and how can I modify them? Seeing how a simple PNG file opens Internet Explorer using Wine, I need to change these settings.

Asked By: MvG

||

Look at the content of the xdg-open file, and you will notice that it is a simple shell script. Its main task is identifying the desktop environment in use, which will then be used to delegate the task to a specific tool:

  • KDE delegates to kde-open or kfmclient
  • Gnome delegates to gvfs-open or gnome-open
  • Mate delegates to gvfs-open or mate-open
  • XFCE delegates to exo-open
  • LXDE delegates to pcmanfm, with fallback to “generic” for most URLs
  • Enlightenment delegates to enlightenment_open
  • Everything else is termed “generic”, and the script tries its own luck

So the core message is this: in most situations, one of these delegates will do the actual work, so you should check about how these are configured.

For example, I’m running XFCE, so xdg-open calls exo-open which uses the XFCE settings available through the XFCE settings user interface and stored in ~/.local/share/applications/mimeapps.list.

For details about the config files in use, strace -e file can be useful. And if you are in the “generic” situation and want to see what xdg-open itself does, you can try sh -x `which xdg-open` file.name.

Answered By: MvG