21

I've created a custom launcher file:

[Desktop Entry]
Type=Application
Name=P4V
Comment=Perforce Visual Client
Icon=/usr/lib/p4v/P4VResources/icons/P4-V_128x128.png
Exec=/usr/bin/p4v
Terminal=false
Categories=Development;

And dragged this file to my launcher. However, when I click the icon, it opens the application under a 2nd, different icon (I click the top one, it opens the application under the bottom one):

launcher icons

The bottom icon isn't present until after I launch the application using the top P4v icon that I manually added.

3
  • 1
    Is this a java app?
    – dobey
    Jul 14, 2015 at 19:53
  • /usr/bin/pv4 is a script that apparently opens your app in some manner that is itself associated with an icon. Probably javascript - perforce.com/product/components/perforce-visual-client
    – doug
    Jul 15, 2015 at 1:24
  • 1
    @doug nope, it is an application with a window and a "normal" .desktop file (including a set icon) in /usr/share/applications (I installed it to find out). Jul 15, 2015 at 4:58

2 Answers 2

12

If an application produces a second icon, not being a generic one

If an application generates a second icon in the Unity launcher other than a a grey, generic icon, there must be already an (other) existing launcher, calling p4v in its main command:

An application's .desktop file by definition has a "main" command in the first line, starting with Exec=. This is the command that is run when the icon is clicked in the (Unity) launcher. Apart from that, a .desktop file can have one or more shortcut- sections, available when you right-click on the representing icon in the Unity launcher.

Multiple .desktop files calling the same application in their main command

The symptoms you are experiencing can happen when more than one .desktop file in either /usr/share/applications or ~/.local/share/applications have the same ("main-") command in their first Exec= line, but the files are differently named.

P4v by default should install (and probably has installed) a .desktop file, named p4vasp.desktop in /usr/share/applications.

How to fix
Your problem should be fixed if you remove your own (probably local) .desktop file, then run p4v from Dash and pin it to the launcher.

What if you want to customize the existing launcher?

If you want to change the .desktop file's behaviour or e.g. its icon:

  • copy the file from /usr/share/applications to ~/.local/share/applications
  • don't change the file's name
  • open the file in gedit (drag it over an opened gedit window) and make the changes you'd like
  • log out and back in, the local version of the .desktop file will overrule the global one.

To revert, simply remove the local one, log out and back in.

Related to this post

2
  • This answer is just as good in Ubuntu 18.04 with GNOME 3
    – Todd
    Jul 25, 2018 at 21:29
  • This answer is incorrect, as one can still end up with two icons in the Unity dock even if there are no duplicate .desktop files, as the other answer points out. It was the case for me. May 16 at 18:45
11

Solution that worked for me on ubuntu 18.04 when struggling with getting an AppImage added to my favorites. This solution is summarised from https://beamtic.com/duplicated-icons-in-launcher

  1. Get window class of your program with double icon by executing

     xprop WM_CLASS
    
  2. Select the main window of that program by clicking on it. The output is of the form

     WM_CLASS(STRING) = "some-thing", "different-thing"
    

Both some-thing and different-thing work.

  1. Add the following line to the .desktop file (I had my .desktop file in ~/.local/share/applications) and replace Name_of_Window_Class with either some-thing or different-thing:

     StartupWMClass=Name_of_Window_Class
    
  2. Start/Restart the application, done!

3
  • Perfect, worked for me. Thanks Feb 9, 2021 at 17:47
  • Worked, needed to solve this for robo3t 1.4 so for others the line is StartupWMClass=robo3t
    – Miroslav
    Mar 29, 2021 at 9:03
  • For my desktop file which has exec line python3 my_script.py, this does not work. I get my_script.py and My_script.py, both do not work.
    – WesternGun
    Jul 29, 2021 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.