8.1 Default Applications
20211012
Often we will choose our favourite
applications as a default for particular tasks. For example, to view
an image in a png
file we might choose to use eog
by default. The command xdg-open can be used to
open files using preferred applications. This command is used, for
example, by browsers to perform tasks and open files using the
preferred application.
We can use xdg-mime to determine the MIME type of a file and for that file type the default application:
$ xdg-mime query filetype sample.png
image/png
$ xdg-mime query default image/png
org.gnome.eog.desktop
Information about the application org.gnome.eog.desktop
can be found
in a file of the same name in /usr/share/applications/
.
$ cat /usr/share/applications/org.gnome.eog.desktop
[Desktop Entry]
Name=Image Viewer
Comment=Browse and rotate images
TryExec=eog
Exec=eog %U
[...]
Thus, both of the following commands run the same application:
$ xdg-open sample.png
$ eog sample.png
To set a default application for a particular MIME type:
$ xdg-mime default image/png eom.desktop
The xdg-open will then use eom
to open a png
file.
Similarly for video:
$ xdg-mime query filetype iris.mp4
video/mp4
$ xdg-mime query default video/mp4
org.gnome.Totem.desktop
Other examples:
$ xdg-open "http://www.example.com" # Open URL using default browser.
Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0