Score:1

GNOME 3 show path to a desktop file seen in launcher?

us flag

I'm using a pretty clean install of Ubuntu 20.04 at the moment, finally though to ask this here since it's been bugging me. Is there a way to find out where a launcher entry's .desktop file is at? In my mind, it should be as easy as right-clicking the icon and selecting an option that called Show .desktop file or something like that.

The inspiration for this question comes from me installing the Spotify snap. I need to add a command-line option since Spotify isn't playing nice with my 4K screen and everything is tiny. The problem is, there are three .desktop files and I'm not sure which is the right one.

$ locate *spotify*.desktop
/snap/spotify/53/meta/gui/spotify.desktop
/snap/spotify/53/usr/share/spotify/spotify.desktop
/var/lib/snapd/desktop/applications/spotify_spotify.desktop

Without some experimentation, I don't have a way of knowing which of these is actually associated with the icon I'm seeing in the launcher. I know I could do something silly like remove the icon entry from them one at a time until I find the "real" one, but I feel like there must be an easier way that I don't know about.

Nmath avatar
ng flag
"*Without some experimentation, I don't have a way*" - So why don't you experiment? You can backup each file and use process of elimination. Just rename the files by putting `.bak` to the end of the filename. They will no longer be `.desktop` files, so you can go one by one and review the effects.
us flag
@Nmath I've experimented plenty before, and it takes a while! Why not search for an easier way to complete a tedious task?
Nmath avatar
ng flag
What I am suggesting is not tedious or time consuming. We can't know how to fix a problem without knowing the cause of the problem. This is why you need to research or experiment.
Score:0
cn flag

For daily use, the operating system should not bother you with a "right-clicking menu showing an option that called Show .desktop file or something like that.". Only the system admin should be concerned with this if there is an issue, but anyway, that is a different discussion.

The .desktop launcher that has precedence is the one that is appearing in your menu. The preference is dictated by the XDG_DATA_DIRS environmental variable. Display it with the command

printenv XDG_DATA_DIRS

Folders where .desktop files reside are existing as a folder applications under the folders listed in XDG_DATA_DIRS.

In your example, only one of the listed .desktop files is residing in an applications folder:

/var/lib/snapd/desktop/applications/spotify.desktop

So I can tell right now that that is the one appearing in your menu.

If you would have a second one living in an applications folder, e.g.

/usr/local/share/applications/spotify.desktop

then you can tell which one is in effect by checking which of the folders /var/lib/snapd/desktop or /usr/local/share comes first in the XDG_DATA_DIRS variable.

us flag
That's perfect, thanks! This is great information because it actually gives me enough to write a GNOME extension that will give me that right-click button of my dreams.
vanadium avatar
cn flag
Great! Success with your extension and make sure to publish it!
in flag
@dustinrichards In the gnome2 era, this operation is easy, This problem is driving me nuts in the gnome3 era, often. have you publish your extension?
in flag
Seems dirs in `XDG_DATA_DIRS` incomplete, For example `~/.local/share/applications` is not in this list
vanadium avatar
cn flag
@yurenchen correct, that one is implicit and not listed in XDG_DATA_DIRS.
Score:0
in flag

According to the information provided by @vanadium
I wrote a little script, to help me locate the app .desktop location, for now.

I wish gome-shell will support it some day, or by some extension.
// maybe I will try to implement it someday..

⇒ Usage demo

## find normal app
 ️  test$ locate_app.sh gedit
/usr/share/applications/org.gnome.gedit.desktop
 
## find snap app
 ️  test$ locate_app.sh firefox
/var/lib/snapd/desktop/applications/firefox_firefox.desktop

## find flatpak app
 ️  test$ locate_app.sh krita
/var/lib/flatpak/exports/share/applications/org.kde.krita.desktop
/usr/share/kservices5/searchproviders/krita.desktop

⇒ The script

Save as locate_app.sh.
// It only search by .desktop file name.


#!/bin/bash

name="$1"

DIRS="
$HOME/.local/share/applications
"
# /usr/share/applications

DIRS="$DIRS ${XDG_DATA_DIRS//:/$'\n'}"

# IFS=:
# DIRS=$XDG_DATA_DIRS
for d in $DIRS; do
    [ -d "$d" ] || continue
    #echo "=== $d"
    find $d -iname "*$name*.desktop"
done | grep -i "$name" --color
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.