3

I created a shell script, let's say it's

echo hi
sleep 5
echo bye
exit

Then I created a .desktop -file to launch the shell script. Double-clicking it works perfectly fine:

[Desktop Entry]
Version=1.0
Name=Test
Comment=Bash Cript
Exec=bash /example/test.sh
Terminal=true
Type=Application
Categories=Utility;Application;

After drag- and dropping the .desktop-File into the Unity Launcher, I can click on it. ONCE. After the first launch, the icon stays in the launcher, but clicking on it doesn't do anything.

Middle-Mouse clicking on it launches the application again

What am I doing wrong?

3
  • Did you create the .desktop file as described here ? Did you add the Type=Application and possibly Terminal=true bits ? Maybe Unity needs them. Jun 16, 2016 at 17:36
  • I did.I just edited my post and added my Desktop Entry.
    – Alex
    Jun 16, 2016 at 17:46
  • Hi @Alex could you mention if you managed? Jun 18, 2016 at 5:54

1 Answer 1

5

It does work

...even tested it, but the launcher icon is unresponsive for about 7 seconds after you clicked. If you click again after these 7 seconds, it will work again.

This "break" is caused by the icon, waiting for a window to appear. This won' t be the case, since the appearing gnome-terminal -window is "claimed" by the gnome-terminal's launcher icon, and your "home-made" icon does not recognize the window as "his".

Solution?

You could solve the issue by adding a line to your launcher (14.04)

StartupWMClass=gnome-terminal

or (16.04):

StartupWMClass=gnome-terminal-server

however, only do this for reasons of testing, don't use this as a permanent solution; having mutiple .desktop files, possibly claiming the same WM_CLASS in their main command is a bad idea, it will cause clashes in how gnome-terminal appears in the Unity launcher.

Better solution

Better add your script as a right-click option to the existing gnome-terminal launcher:

enter image description here

  1. Copy the global gnome-terminal launcher from /usr/share/applications to

~/.local/share/applications:

    cp /usr/share/applications/gnome-terminal.desktop ~/.local/share/applications
  1. Open the file with gedit:

    gedit ~/.local/share/applications/gnome-terminal.desktop
    
  2. Change the line:

    Actions=New;
    

    into:

    Actions=New;My Script;
    

    and add the section:

    [Desktop Action My Script]
    Name=My Script
    Exec=gnome-terminal -e "bash /absolute/path/to/your/script.sh"
    

    to the very end of the file. Then log out and back in, and you'll have your script available as a quicklist- shortcut in the gnome-terminal launcher.

2
  • I cannot agree on the "if you click again after 7 seconds"-part. Adding "StartupWMClass=gnome-terminal" does not seem to change anything. Anyway: Adding the script as a seperate action is working. But that's not what i'm looking for, as i want to be able to define an icon.
    – Alex
    Jun 24, 2016 at 18:06
  • @Alex You didn't mention your Ubuntu version.If it is 16.04, it should be gnome-terminal-server, as mentioned, that is a bad solution however. Jun 24, 2016 at 19:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .