Why is there two instances of "Okular" and how do I get rid of the other one?

Solution 1:

NOTE: This answer works for the okular snap in Xubuntu 20.04, and in Ubuntu 20.04

After installing okular as a snap package, I see two icons in the Whisker Menu launcher: one seems to represent okular and the other is generic but both show the same tooltip (Universal document viewer).

Two okular icons

I ran locate -i okular | grep -i desktop to identify the corresponding .desktop files. (Ubuntu users may need to install the mlocate package to access the locate command.) There were several hits but

/var/lib/snapd/desktop/applications/okular_okular.desktop
/var/lib/snapd/desktop/applications/okular_org.kde.okular.desktop

are relevant.

  • I copied these two .desktop files over to ~/.local/share/applications. The applications subfolder may not exist originally in which case it should be created.

  • I edited both files to remove extra names, generic names, and comments and then compared the two files.

dkb@dkb-xubuFF:~/.local/share/applications$ ls
okular_okular.desktop  okular_org.kde.okular.desktop
dkb@dkb-xubuFF:~/.local/share/applications$ diff *.desktop
7,8c7
< Exec=env BAMF_DESKTOP_FILE_HINT=/var/lib/snapd/desktop/applications/okular_okular.desktop /snap/bin/okular %U
< Icon=/snap/okular/98/usr/share/icons/hicolor/64x64/apps/okular.png
---
> Exec=env BAMF_DESKTOP_FILE_HINT=/var/lib/snapd/desktop/applications/okular_org.kde.okular.desktop /snap/bin/okular %U
12d10
< 
dkb@dkb-xubuFF:~/.local/share/applications$ 

As you can see from the output,

  • the Exec= lines of both .desktop files launch /snap/bin/okular %U
  • one .desktop file, okular_org.kde.okular.desktop, is missing the line beginning with Icon and that explains the "generic" icon in the application menu.
  • since both .desktop files seem to be equivalent, we can just "hide" the one which shows the generic icon by adding NoDisplay=true as the last line to that .desktop file.

Now, there's just the one "okular" when one types oku in a launcher's search bar:

Just one okular

Note:

  • none of the operations above need the user to be root or to invoke sudo
  • modifications made to .desktop files in ~/.local/share/applications will survive updates of the parent packages.

A bug has been filed.