16

Given xdg-open and an extension, is there a way to get the application which xdg-open is set to for that particular extension?

For example given xdg-open and .jpg the result is eog.

2
  • 1
    Which OS are you using? Commented Jul 24, 2016 at 11:27
  • This is Ubuntu Trusty. Commented Jul 24, 2016 at 11:29

2 Answers 2

19

AFAIK the choice of action is based on the file's mimetype rather than its extension.

At least on Ubuntu, you should be able to use the query action of xdg-mime to show the default application for a specific mimetype

$ xdg-mime query default image/jpeg
eog.desktop

You can check the mimetype for a particular file using xdg-mime query filetype e.g.

$ xdg-mime query filetype kqDRdnW.jpg
image/jpeg

or using the file command e.g. file --mime-type <file>

See man xdg-mime for further usage information.

4
  • probably worth mentioning to the OP that the way you get the mime-type for the filetype jpeg is xdg-mime query filetype <file_you_want_the_mimetype_of> Commented Jul 24, 2016 at 12:21
  • @the_velour_fog good point - added Commented Jul 24, 2016 at 12:24
  • Unfortunately xdg-mime query default doesn't always work if xdg-open just calls an underlying tool (eg pcmanfm); the example you used in your answer returns nothing on my LXDE system. Commented Jul 24, 2016 at 12:49
  • Thankyou, I would go first option here, var="xdg-mime query default image/jpeg" && $(${var%.desktop}) Commented Jul 24, 2016 at 15:37
8

To query the mime type used by an existing file by using xdg-utils, it works as:

$ xdg-mime query filetype yourfile.xxx

You can also set a new default, for instance to change an associated desktop entry by setting Thunar - a modern file manager for the Xfce Desktop Environment - as the default file browser you should enter:

$ xdg-mime default Thunar.desktop inode/directory

Or for example to set the default application for http(s):// internet protocols, you can use:

$ xdg-mime default midori.desktop x-scheme-handler/http

OR

$ xdg-mime default midori.desktop x-scheme-handler/https
3
  • This isn't limited to rpm based systems; it's part of the standard desktop and works on Debian (for example). Unfortunately this is how to set a default value; it doesn't say how to find what value is set. And xdg-mime query default doesn't always report what it will do if xdg-open calls an underlying desktop program (eg pcmanfm on LXDE). Commented Jul 24, 2016 at 12:47
  • @StephenHarris I thought options might be different. Thanks for telling me. Commented Jul 24, 2016 at 13:01
  • This should be the accepted answer. Commented Jul 10, 2018 at 1:56

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.