XDG/Software
This page describes various command-line programs for managing and using default applications for particular MIME types, in the context of standards/specifications by freedesktop.org, previously known as the X Desktop Group.
Most of the programs described in this page are provided by the x11-misc/xdg-utils package; exceptions are noted.
Programs
xdg-open(1)
The xdg-open(1) program can be used to open a file or URL in the default application for that resource:
user $
xdg-open file.txt
This will open file.txt in the preferred application for text/plain
files, e.g. Kate or GEdit.
user $
xdg-open https://www.gentoo.org/
This will open https://www.gentoo.org/
in the preferred Web browser, e.g. Firefox.
xdg-mime(1)
The xdg-mime(1) program is the primary way to manage default desktop applications from the command line.
It can be used to query the MIME type of file:
user $
xdg-mime query filetype image.ext
image/tiff
Note, however xdg-mime takes a file's extension at face value, so if the file image.ext in the previous example was renamed to image.jpg, xdg-mime reports an incorrect file type:
user $
xdg-mime query filetype image.jpg
image/jpeg
file(1), however, will report the correct file type:
user $
file image.jpg
image.jpg: TIFF image data, big-endian
xdg-mime can also be used to query the default application for a particular MIME type:
user $
xdg-mime query default image/tiff
org.pwmt.zathura.desktop
To set the default application for a MIME type, specify the relevant .desktop file:
user $
xdg-mime default nsxiv.desktop image/tiff
Available .desktop files can be found in /usr/share/applications/ and (by default) ~/.local/share/applications/. However, as the xdg-mime(1) man page notes,
[t]he application's desktop file must list support for all the MIME types that it wishes to be the default handler for.
xdg-settings(1)
The xdg-settings(1) program can be used to set the default browser:
user $
xdg-settings set default-web-browser firefox-bin.desktop
It can also be used to set the default handler for a particular URL scheme, e.g. mailto
:
user $
xdg-settings set default-url-scheme-handler mailto balsa.desktop
See also
- XDG — the X Desktop Group, now known as freedesktop.org
- XDG/Base Directories — standard directories specified by freedesktop.org (formerly the X Desktop Group)
- XDG/xdg-desktop-portal — a frontend to implementations of the xdg-desktop-portal interface.