4

Am making an application in Python and I need to provide "Open with" menu to user. Currently I am parsing /usr/share/applications/mimeinfo.cashe and ~/.local/share/applications/mimeapps.list but with very poor results. Nautilus has more entries in "Open with" menu.

Do you know a better way for getting list of applications associated with file?

Edit:

There is a simpler way using gnomevfs module.

mime_type = gnomevfs.get_mime_type(filename)
application_list = gnomevfs.mime_get_all_applications(mime_type)

In returned list you get application name, icon name, config file and many other stuff.

MeanEYE
  • 967
  • 8
  • 24
  • 1
    This question is essentially the inverse of this one: http://askubuntu.com/questions/205984/get-a-list-of-file-types-that-can-be-opened-with-a-specific-application/206027#206027 – Anderson Green Oct 25 '12 at 02:27

2 Answers2

4

I've found a bit more elegant solution. In gnomevfs module there is function named mime_get_all_applications which returns proper list of associated applications.

More information can be found here.

Edit: Since the time this answer was written, GnomeVFS was marked as deprecated. GIO does provide this functionality now with methods like app_info_get_all and app_info_get_for_type.

MeanEYE
  • 967
  • 8
  • 24
2

GNOME stores its application lists in those two files:

/etc/gnome/defaults.list
~/.local/share/applications/mimeapps.list

(link to source)

Andrea Spadaccini
  • 12,378
  • 5
  • 40
  • 54