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]
text/plain=emacs.desktop
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:
- How does
xdg-open
determine which application to launch when there is nodefaults.list
andmimeapps.list
? - Why is
xdg-open
using firefox when I simply write/usr/share/applications/defaults.list
?
I am using Arch linux.
Best Answer
If using
xdg-open
to open applications, then usexdg-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:
Example changing the default file manager for opening directories (could choose caja.desktop (default for mint), nautilus.desktop (ubuntu), etc:
And also do
locate -i foo.desktop
to verify thatfoo.desktop
does in fact exist.More to the point, in order to see what the default text editor is,
To use a different default text editor (again, verifying that the ".desktop" file exists):
Now, either double-clicking "foo.txt" (in your GUI file manager) or running
xdg-open foo.txt
will usegvim
instead ofgedit
.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.,Further, this silently fails to work as expected if the ".desktop" file does not exist:
The actual emacs ".desktop" file (in my env):
See also: https://wiki.archlinux.org/index.php/xdg-open