Configuring default applications for <code>xdg-open</code>
source link: https://200ok.ch/posts/2022-01-12_configuring_default_applications_for_xdg_open.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
xdg-open
Configuring default applications for xdg-open
2022-01-12 - 380 words - 3 min read
When you open a file in Linux, the question arises: Which of the available applications should be opened? Usually, this question is deferred to xdg-open. But, how does xdg-open
know which application is the right one and how do you configure the one you want to use instead?🤓
To get started, try opening your file like so: xdg-open your_path
. This is just to confirm what application is opened right now. To configure a different application, first, we have to know about the mimetype of your_path
. In this example, I'm asking for the mimetype of an image:
So, the mimetype is image/jpeg
. Now we can ask how xdg comes up with the responsible application:
We are increasing the debug level with XDG_UTILS_DEBUG_LEVEL=3
to list the responsible application, and the paths to the config files.
Finally, we can set a new default application. Suppose you want to open jpegs with imv in the future. You will add the responsible desktop entry file. My distribution (Debian) usually ships with a desktop entry file for every package. The Debian package for imv does include a imv.desktop
file. Here's how to configure imv as the default for image/jpeg
files, then:
This will add the following line to one of your mimeapps.list
config files (i.e. .config/mimeapps.list
):
How to create a custom desktop entry file
If an application doesn't have a desktop entry file, or you want to create a custom configuration for your needs, just create a new file in ~/.local/share/applications
.
Here is an example of creating a desktop entry file for Emacs, but instead of running Emacs (which would be the default), it uses emacsclient
. I'm using this config for all kinds of mimetypes (directories, zip files, etc).
If you liked this post, please consider supporting our Free and Open Source software work - you can sponsor us on Github or star our FLOSS repositories.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK