Ubuntu – How to find the .desktop information for a given binary


Given the path to an executable (say /usr/bin/gvim), how can I find the Gnome .desktop file for that application?

I'm futzing around in python, so a python-specific answer would be most helpful.

Best Answer

If you want to do it programmatically, use python-gmenu. It wraps the libgnome-menu2 API for Python.

That API lets you iterate over all the desktop directories that are currently configured and includes any overrides or modifications the user has customized. Then you just query each file to see if it's Exec line matches what you expect.

I couldn't find any documentation for either library, but liberal use of "import gmenu; dir(gmenu)" and looking over /usr/include/gnome-menus/gmenu-tree.h should help.