4

I can list the mimetypes potentially handled by a .desktop file doing something like this:

$ grep 'MimeType' /usr/share/applications/eog.desktop | tr ';' '\n'
MimeType=image/bmp
image/gif
image/jpeg
image/jpg
image/pjpeg
image/png
image/tiff
...

And I can show what the default application is for a given mimetype with gvfs-mime:

$ gvfs-mime --query image/tiff
Default application for 'image/tiff': eog.desktop
Registered applications:
        eog.desktop
        gimp.desktop
...
Recommended applications:
        eog.desktop
        gimp.desktop
...

or with gio:

$ gio mime image/tiff
Default application for “image/tiff”: eog.desktop
Registered applications:
    eog.desktop
    gimp.desktop
...
Recommended applications:
    eog.desktop
    gimp.desktop
...

But how do I list the mimetypes that eog.desktop actually handles?

1 Answer 1

3

I don't know of any tool that does that.
You could write your own though. Here is a very simple python3 script that should run on any system that uses GIO underneath (e.g. Gnome 3):

#!/usr/bin/env python

from sys import argv
from gi.repository import Gio

app = argv[1]
glauncher = Gio.DesktopAppInfo.new_from_filename(app)
for mtype in Gio.AppInfo.get_supported_types(glauncher):
    ghandler = Gio.AppInfo.get_default_for_type(mtype, False)
    launcher = glauncher.get_executable()
    handler = ghandler.get_executable()
    if launcher == handler:
        print (mtype)

The script takes one argument: the full path to your desktop file

myscript /usr/share/applications/eog.desktop

The script gets the list of mime types that your application supports, then, for each item in the list, it gets the default handler and if it's the same application, it prints the mime type.


I guess you could also try to parse mimeapps.list, mimeinfo.cache or defaults.list (the latter is deprecated, see freedesktop.org spec for possible file names and locations) and extract the relevant information from there but your results may vary as on some distros some of those files are missing.

3
  • I was hoping a command could check the appropriate files and handle precedence automatically, but this is a good explanation for how to do it manually. Sep 10, 2015 at 14:14
  • @bariumbitmap - I don't know of any command that does what you want, I have updated my post though. Sep 10, 2015 at 21:25
  • 1
    That does the trick. I happen to use XFCE, but all I needed was the python-gi package, so life is good. Sep 10, 2015 at 23:30

You must log in to answer this question.

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