7

How to find all programs associated with a MIME type? One could look for the MIME type in the default, system-wide directory. For example, for application/pdf,

grep -ls application/pdf /usr/share/applications/*

lists all the program files in /usr/share/applications that are associated with application/pdf.

But that would overlook other directories, specially user-level directories.

Isn't there a command similar to

xdg-mime query default application/pdf

to list all associated programs, not only the default one?

Quasímodo
  • 2,017

1 Answers1

9

Here's a short Python program for that:

#!/usr/bin/env python3

from gi.repository import Gio import sys

if len(sys.argv) != 2: print('Error: Exactly one command line argument needed') sys.exit(1)

for app in Gio.app_info_get_all_for_type(sys.argv[1]): print(app.get_id())

Save that in a file, e.g. /usr/local/bin/mimeapps. Then you can use it like

$ mimeapps text/plain  
emacs.desktop
libreoffice-writer.desktop
pluma.desktop
vim.desktop
  • If you haven't installed PyGObject (which provides the gi module), you can do so with: sudo apt install libgirepository1.0-dev; pip install PyGObject – mmigdol Apr 10 '23 at 18:54