2

I made a .desktop file to be able to launch my python script from the launcher bar.

I set the python script as an executable and it runs fine if I double click and run it from the file manager. It also runs fine from terminal.

The desktop file is located in /.local/share/applications/ and looks like:

[Desktop Entry]
Version=1.0
Name=Simple Timer
Comment=Timer
Exec=python3 /home/user/app/timer.py
Icon=/home/user/app/icon/timer.png
Path=/home/user/app/timer/
Terminal=false
Type=Application
Categories=Utility;Application;

If I search "Timer" in Dash, it shows up. I can run it from there. Running it would create two duplicate icons on the launcher bar as pictured.

enter image description here

  • First icon will pulsate for about 10 seconds and then disappear. This icon is lockable to the launcher. If this icon is locked to the launcher bar, it will also pulsate for a few seconds after the application window closes, during which, it will be unclickable.
  • Second icon is not lockable to the launcher and will only disappear if the application window is closed.

If I run the script from file manager. It creates 1 launcher icon that behaves normally.

I have verified that there are no duplicate .desktop files in /usr/share/applications/. My created .desktop file only exists in /.local/share/applications/ and if removed, I will no longer be able to search for my timer on Dash or lock it to launcher bar.

How can I fix both the pulsating/unclickable issue and the double icon issue here?

2

Launcher does not recognize the window as "his"

Specifically Tkinter windows do not recognize their "own" window (class). This makes the icon blink in vain, waiting for its window. Once the window appears, the launcher doesn't recognize its own window and pops out of the launcher when timeout has passed. Since a "normal" window is always represented by an icon in the launcher, you are left with a generic icon (usually, if there is no duplicate launcher) or a different one (see further below).

You can simply fix that by adding:

StartupWMClass=Tk

to your launcher (since it is a Tkinter window)

Look at the difference (I gave the launcher the firefox icon for testing):

  1. without the line, when opening multiple windows. Watch the three generic icons + a blinking firefox icon, disappearing after 10 seconds or so.

    enter image description here

  2. Now I add the line StartupWMClass=Tk, all windows are grouped in the same icon:

    enter image description here

Why no generic icon in your case?

Adding the WM_CLASS to your .desktop file will fix your issue. I am pretty sure however, you accidentally created an extra launcher (or have Unity created one automatically). Look in /.local/share/applications/ and make your launchers executable. The icon will show. Most likely, your dupe will have "unity" in its name.

In general, how to find the WM_CLASS of a window?

  • Open a terminal, type

     xprop WM_CLASS
    
  • Subsequently click on the window. two strings appear, separated by a comma. The one in Title case is the one yoiu need to add.

Notes

Not your issue, but:

You don't need to set the lines below:

  • Version=1.0 (no harm, but not needed)
  • Since your script is executable, you don't need python3 (you can have the script call the interpreter directly)
  • Path=/home/user/app/timer/ (unnecessary)
  • Terminal=false (this is the default)
  • You're spot on! Adding StartupWMClass=Tk helps the launcher recognize the new window and everything is fine now. Regarding the extra lines, I find it odd that if I remove the Path=... line of codes, the launcher will flash and not launch at all. I think you answered this in another post already so I will do some more digging. – Minh Tran May 19 at 8:35
  • I also want to add that the only file in my /.local/share/applications/ directory is my timer.desktop file. Making that file executable will change its icon from a generic desktop file icon to my script icon. Maybe I dont get a generic icon because of the way the icon is set in my python script? – Minh Tran May 19 at 8:46
  • Ah, you set one in your script? That is the explanation! – Jacob Vlijm May 19 at 9:00

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.