Python: get list of file related applications (Linux)

We are making a Python application, and I need to provide the user with the "Open" menu. I am currently parsing /usr/share/applications/mimeinfo.cashe and ~/.local/share/applications/mimeapps.list , but with very poor results. Nautilus has more entries in the Open With menu.

Do you know the best way to get a list of applications related to a file?

Edit:

There is an easier way to use the gnomevfs module.

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

In the returned list, you will receive the application name, icon name, configuration file and much more.

+4
source share
2 answers

I found a slightly more elegant solution. The gnomevfs module has a function called mime_get_all_applications that returns the correct list of related applications.

More information can be found here .

Edit: Since writing this answer, GnomeVFS has been marked as deprecated. GIO now provides this functionality with methods such as app_info_get_all and app_info_get_for_type .

+4
source

GNOME stores its application lists in these two files:

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

(link to source)

+2
source

Source: https://habr.com/ru/post/1344814/


All Articles