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?


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

jinx:735 Z$ xdg-mime query default application/pdf  
  • 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 Mar 8 '11 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 Mar 8 '11 at 3:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.