5

Context

I'm using GNOME 3.22 and I want to organize all desktop files in groups. To do so, I must list all desktop files that appears in the application menu and use some command from this guide to organize them.

I've discovered that there're 3 places that contain these desktop files:

~/.local/share/applications
~/.local/share/flatpak/exports/share/applications
/usr/share/applications

Using this script, I half-succeed. However, there're still some items that doesn't belongs to any group:

  • These desktop files don't have any Categories field so I cannot rule over them by category

  • These desktop files don't belong to any directory I listed above so I cannot call their names

Question

Apparently, GNOME doesn't list desktop files just from directories above. There must be some place that store them, the desktop shell just need to read it to list all applications. I just cannot see it. Could you please let me know where is it?

Update

This is my "half-success": GNOME Apps Menu

4
  • Have you tried alacarte? It might help you instead of do manually the job Feb 14, 2017 at 14:08
  • There's a tool called find that can find any .desktop file on your sytem... Feb 14, 2017 at 15:00
  • @don_crissti Doing find at root would take a lot of time, and I don't run my script just once but every time I add an application. There must be a place where the desktop shell (e.g. gnome-shell) just need to look at it to list all these applications.
    – DMaster
    Feb 14, 2017 at 16:44
  • 1
    per the standards the default places are $XDG_DATA_HOME and $XDG_DATA_DIRS - now, whether your distro/setup is using some additional location is another question (and the reason I suggested find - you don't have to use it everytime you add an application but just once to see where those files are though again, the standard locations are those mentioned in your post) Feb 14, 2017 at 17:44

4 Answers 4

4

Instead of searching the filesystem yourself, you could use the Gio library (part of Gtk/GObject/GLib ecosystem on which Gnome is built). You can use this through Python on any Gtk-based desktop environment such as Gnome, Xfce, MATE, Cinnamon etc. Python with gi module should be available without needing to install anything.

from gi.repository import Gio

all_apps = Gio.AppInfo.get_all()  # Returns a list of DesktopAppInfo objects (see docs)

# For example, print display name and description of all apps
for app in all_apps:
    print(app.get_display_name())
    print(f"\t{app.get_description()}")

API docs: Gio.AppInfo, Gio.DesktopAppInfo

DesktopAppInfo inherits from AppInfo. I haven't been able to find what other kinds of AppInfo there might be. The objects returned by Gio.AppInfo.get_all seem to all be Gio.DesktopAppInfo instances. As far as I can tell, we are mostly dealing with DesktopAppInfo instances.

The DesktopAppInfo objects represent all the .desktop files that it found on your system. They have properties that you can access using get_* methods, representing pretty much everything that's in the .desktop file.

You can get properties of AppInfo objects such as name, display_name (usually the same as name but sometimes different), commandline (full command line with arguments that gets called to run the app), executable (just the command, no arguments), description, etc. See the get_* methods in the API docs, starting from Gio.AppInfo.get_commandline on.

And from DesktopAppInfo, everything that's in AppInfo, plus: categories, generic_name, keywords, startup_wm_class, etc. See Gio.DesktopAppInfo.get_action_name onwards

2

The free desktop specification for the Applications menu search path is here. The short answer to your question is append "applications" to every directory in the search path $XDG_DATA_DIRS.

1

This link may help with desktop files that don't have any "Category" field: https://wiki.gentoo.org/wiki/Gnome_Applications_Folders

0

I know I'm late to the party, but maybe this answer helps someone later in time.

To find all desktop files in your system:

find / -iname "*desktop" -type f -not -path "/media*" 2> /dev/null

The command above lists all desktop files in your system. If you want to find a specific application (replace <application-name> with your application name or even part of its name, and remove the <>):

find / -iname "*desktop" -type f -not -path "/media*" -exec grep -il <application-name> '{}' ';' 2> /dev/null

Hope this helps someone someday.

You must log in to answer this question.

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