Search code examples
pythonlinuxopen-with

Python: Get list of applications associated with file (Linux)


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.


Solution

  • 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.