Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

When I have no defaults.list and mimeapps.list, xdg-open opens text/plain with gvim. But when I create defaults.list in /usr/share/applications/ and add the following lines :

[Default Applications]

it opens text files with firefox.

However, if I move /usr/share/applications/defaults.list to ~/.local/share/applications/mimeapps.list, it opens text files with emacs as expected.

My questions:

  1. How does xdg-open determine which application to launch when there is no defaults.list and mimeapps.list?
  2. Why is xdg-open using firefox when I simply write /usr/share/applications/defaults.list?

I am using Arch linux.

share|improve this question
I use Openbox. Also, I noticed a /usr/share/applications/ file which seems to list the default applications. It is even more confusing... – Gradient May 26 '13 at 18:12

1 Answer 1

If using xdg-open to open applications, then use xdg-mime to set the default application for a given mime type (typically, installing xdg-utils gives you the xdg-mime and related programs).

For example, to see the "filetype" (mime-type, if you will) of given file:

$ xdg-mime query filetype tmp.txt

$ xdg-mime query filetype foo.pdf 

$ xdg-mime query filetype $PWD

Example changing the default file manager for opening directories (could choose caja.desktop (default for mint), nautilus.desktop (ubuntu), etc:

$ xdg-mime default Thunar.desktop inode/directory

And also do locate -i foo.desktop to verify that foo.desktop does in fact exist.

More to the point, in order to see what the default text editor is,

$ xdg-mime  query default text/plain 

To use a different default text editor (again, verifying that the ".desktop" file exists):

$ locate -i vim.desktop

$ xdg-mime default gvim.desktop text/plain

Now, either double-clicking "foo.txt" (in your GUI file manager) or running xdg-open foo.txt will use gvim instead of gedit.

Troubleshooting: be sure that the ".desktop" file for a given application can be found, since that has to be used with the xdg-mime utility; e.g.,

$ xdg-mime default emacs text/plain 
xdg-mime: malformed argument 'emacs', expected *.desktop

Further, this silently fails to work as expected if the ".desktop" file does not exist:

$ locate -i emacs.desktop

$ xdg-mime default emacs.desktop text/plain  # won't work

The actual emacs ".desktop" file (in my env):

$ locate -r 'emacs.*\.desktop'

$ xdg-mime default emacs24.desktop text/plain  # does work

See also:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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