1

I created a custom .desktop entry in my home directory ~/.local/share/applications/startMyApp.desktop I created it so that it would use an xterm instead of gnome-terminal. I want it to have a different look in the dock from my gnome-terminals that I use interactively.

The startMyApp.desktop looks like:

[Desktop Entry]
Type=Application
Name=MyScript
Terminal=false
Exec=xterm -e myScript.sh
Icon=myIcon.png

I have created an icon file in ~/.icons/myIcon.png

The icon appears correctly in the default file browser. When opened from a file browser, it executes the script in an xterm as expected, however, the icon in the dock appears as some other generic xterm icon. Where does that icon comes from? Is it embedded in the binary?

How can I change this? I want the icon in the dock to appear that same as the one specified in the .desktop file. Applications bundled with Ubuntu have the same icon in the dock when launched (aside from the red dots indicating how many windows are open).

pomsky
  • 68,507
jct70
  • 13

1 Answers1

0

You need to add a proper StartupWMClass entry to your .desktop file. To do this follow the steps below.

  1. Launch the application in question.
  2. Launch a separate Terminal window and run xprop WM_CLASS.
  3. Place the cursor over the opened application window in question. The cursor should turn into a crosshair by now. Click. You should get a WM_CLASS string for the application in the Terminal window.
  4. In the .desktop file add the following line

    StartupWMClass=OBTAINED-VALUE
    

    In place of OBTAINED-VALUE put a value you got from step 3 without any quotes.


Update from the OP:

also it seems I needed to provide a name for the xterm instance. The exec line now looks like xterm -name myApp -e myScript.sh

pomsky
  • 68,507
  • 1
    Thanks! A couple things. the full path did not help and was not necessary, ~/.icons is a standard directory to search for single user use, also it seems I needed to provide a name for the xterm instance. The exec line now looks like xterm -name myApp -e myScript.sh – jct70 Jun 01 '20 at 16:22
  • @jct70 Thanks for the feedback, I removed the redundant first part while expanding the second part and also appended your suggestion to the answer. – pomsky Jun 01 '20 at 16:57