5

Is there a linux API that can find the default application for a MIME type? Then I can use this application to open a file.

I can not use xdg-open(url) because the file format is a wrapper format and shared mime-type can only tell the wrapper MIME type. The embedded mime type can only be got from the wrapper file header.

The process would be like: 1. find embedded mime type 2. mime-open(embedded mime type, url)

Is it possible?

1
  • I can't find the MIME type for a pdf extension. So I the question is worthless to me, and also the answer. Commented Feb 1, 2023 at 15:59

1 Answer 1

12

The xdg-mime command is used to query or set file associations.

jinx:735 Z$ xdg-mime query default application/pdf  
evince.desktop
2
  • 1
    This is a good answer, because this program is specifically designed to work across popular desktop environments (KDE, Gnome, others). It's part of a set of related tools called "Portland", a.k.a. xdg-utils, from portland.freedesktop.org/wiki.
    – mattdm
    Commented Mar 8, 2011 at 3:24
  • Also note that it's a (long) shell script, so if you want to find out how to get the information for a specific desktop environment, you can read it to find out.
    – mattdm
    Commented Mar 8, 2011 at 3:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .