Automatically copy .desktop file to .local/share/applications

When I install a snap its .desktop icon is copied to: /var/lib/snapd/desktop/applications/
But it won’t appear in the GNOME’s results for launching applications until I manually copy it to either /usr/share/applications or ~/.local/share/applications

Is there a way to make the .desktop files of installed snaps be copied to GNOME’s /usr/share/applications folder automatically?

Try adding a desktop entry under the apps entry, so that you have something that looks like:

apps:
    my-app:
        command: usr/bin/my-app
        desktop: usr/share/applications/my-app.desktop

If you are using appstream, there are a couple of other features coming that simplify this story Adopt info from other metadata sources

In which file should I do that?
Notice I’m not developing an app for Snap, I’m a user, I’m only installing
apps from the Snap store.

Sorry, I was speaking from a developer’s point of view, as a user, ensure /var/lib/snapd/desktop is part of XDG_DATA_DIRS.

If you installed snapd and immediately installed a snap following this they would not show up given how environment variables work but session logout followed by a login would remediate this.

Thanks! Will try that.

INFO:

OS="Debian GNU/Linux 10 (buster)"
DEBIAN PACKAGE=snapd/stable,now 2.37.4-1+b1 amd64 [installed]
SNAP CORE VERSION=installed:          16-2.46.1                              (9993)
APT REPOSITORIES:
deb http://ftp.br.debian.org/debian/ buster-backports main contrib non-free
deb-src http://ftp.br.debian.org/debian/ buster-backports main contrib non-free
deb http://ftp.br.debian.org/debian/ buster main contrib non-free
deb-src http://ftp.br.debian.org/debian/ buster main contrib non-free
fpc-deb@deb-msi:~$ echo "$XDG_DATA_DIRS"
/usr/share/gnome:/usr/local/share/:/usr/share/

I’ve had similar problems, but already tried restarting and setting $XDG_DATA_DIRS to the described directory in some options:

/etc/profile
/etc/enviroment
/etc/X11/Xsession -> Broke XORG, still trying

XDG_DATA_DIRS:$XDG_DATA_DIRS:/var/lib/snapd/desktop

WORKAROUND: fpc-deb@deb-msi ~ $ sudo ag "XDG_DATA_DIRS=" / 2>/dev/null | grep -v snap Which showed to me:

/etc/X11/Xsession.d/55cinnamon-session_gnomerc:17:      XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/
/etc/X11/Xsession.d/55cinnamon-session_gnomerc:19:      XDG_DATA_DIRS=/usr/share/gnome:"$XDG_DATA_DIRS"

but not necessarily will be the same for other people.

So my </etc/X11/Xsession.d/55cinnamon-session_gnomerc> final result was:

if [ -z "$XDG_DATA_DIRS" ]; then
      XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/
    else
      XDG_DATA_DIRS=/usr/share/gnome:"$XDG_DATA_DIRS"
    fi
    XDG_DATA_DIRS="$XDG_DATA_DIRS":/var/lib/snapd/desktop

OBS: I’m posting this, since this was the only hint i found on solving this problem. I’m guessing snap should have created a file on /etc/X11/Xsession.d/? OBS2: I tried reinstalling sudo apt reinstall snapd, which didn’t work.

Result:

fpc-deb@deb-msi ~ $ echo "$XDG_DATA_DIRS"                      
/usr/share/gnome:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop

So, “SOLVED” :smiley: