2

How can I without any manual GUI use check what will open file with a specific file extension - for example .rb?

Not a duplicate of how can I change file association globally? as mine is about programmatically reading, not changing in any way, including manual through GUI (though https://askubuntu.com/a/289339/349903 hints that parsing some set of config files may give an answer)

To avoid XY problem: I have system installation script, that works fine except that Okular ends associated with .rb, .py, .txt and other text files, instead of text editor. I want to rerun installation script and log what is now opening specific file extensions after every step. I hope that will allow me to debug what is going wrong.

1 Answers1

6

To sum up the comments above the answer to this problem is a two step process:

First determine the MIME type of the file:

MIMETYPE=$(xdg-mime query filetype "<your-file-here>")

Then get the default application associated with this type:

xdg-mime query default "$MIMETYPE"

So the mime type could be text/x-python for example and the application would be gedit.desktop on my system.

You can also make this a one liner:

xdg-mime query default "$(xdg-mime query filetype '<your-file-here>')"
mark
  • 488
  • 4
  • 10