4

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.

1

5 Answers 5

3

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.

1
  • Excellent! That's exactly what I was looking for! Thanks!
    – Erigami
    Feb 13, 2011 at 21:58
2

If your package is installed from package (not from source), you can use (in Bash):

dpkg -L $(dpkg -S /usr/bin/pidgin | cut -f1 -d: ) | grep \.desktop$

In the case of gvim, it outputs nothing. You have another problem, in fact, gvim is an alternative. The "true" gvim can be multiple programs. On my computer it is /usr/bin/vim.gnome. Let's try with it. This doesn't work either... because there is no .desktop in the same package that vim.gnome. In fact, in this complicated case, the .desktop is in another package common to all graphical interfaces of Vim: vim-gui-common

1

The .desktop files for most applications are stored in:

/usr/share/applications

some .desktop files may also be stored in:

/usr/local/share/applications

or (for per user settings) in:

~/.local/share/applications
2
  • Can't .desktop also be installed in the user's home directory? I'd rather not walk every file in every possible install location to track down a path if it's available from some service.
    – Erigami
    Feb 12, 2011 at 18:28
  • See edit. The location of .desktop files cannot be extracted from the installation path, I'm afraid (but should be defined in the .deb package).
    – Takkat
    Feb 12, 2011 at 18:43
1

You can search through all desktop files. For example, to find the desktop file related to gedit:

grep -li exec=gedit $(locate -r '\.desktop$')
0

You can execut 1.sudo find /path_to_folder/ -iname *.desktop in general. And 2.sudo find / -iname *.desktop in your case.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .