Create desktop shortcut launcher for shell script


(Alfredo) #1

Hi guys, I’m trying to create a desktop shortcut launcher for a shell script (let’s say squirrel-sql.sh)

I drag and drop an app from the menu (following http://www.ubuntubuzz.com/2015/08/beginner-lxqt-desktop-usage-guide.html) to have an example to work with.

ie) ~/Desktop/org.kde.ark.desktop

Then I make a copy (~/Desktop/squirrel.desktop) and change the Exec entry to /opt/squirrelsql/squirrelsql-3.9.1-optional/squirrel-sql.sh (and the Name and GenericName entries)

But if click on the desktop icon nothing happens (in the squirrel one, the ark one works ok).

I have tried a lot of things but nothing seems to work.

Any help will be appreciated.


(Pedram Pourang) #2

If the sh file isn’t executable, nothing should happen. Use sh .../squirrel-sql.sh for Exec.


(Jim Shriner) #3

make sure your script is executable. also check your permissions for the script file. I have scripts in the opt directory, owned by root, but right click file property permissions for “view, change, and execute” are “anyone, only owner, and anyone”.


(Alfredo) #4

Thanks for the answer!!! I already tried that without luck.

The file is executable, I’m running it from a terminal.

If I prefix with sh nothing happens when click in the icon (similar behaviour).

Regards


(Alfredo) #5

Thanks for the answer!!! The file is executable, I’m running it from a terminal.


(Alf Gaida) #6

The answer is dead easy - use a paste service like https://paste.ubuntu.com and paste the content of the desktop file. Right now we can only guess. And, ofcourse, give the obvious suggestion: Read and understand the .desktop file spec.


(Alfredo) #7

alfredo@s-nm-anderson-plx:~/Desktop$ cat squirrel.desktop | grep -vE “Comment[|Name[”

[Desktop Entry]

MimeType=application/x-tar;…

GenericName=Squirrel

Name=Squirrel

Exec=/opt/squirrelsql/squirrelsql-3.9.1-optional/squirrel-sql.sh

Icon=ark

X-DocPath=ark/index.html

Type=Application

Terminal=false

X-DBUS-StartupType=Multi

X-DBUS-ServiceName=org.kde.ark

Categories=Qt;KDE;Utility;Archiving;Compression;X-KDE-Utilities-File;

InitialPreference=3

Comment=Work with file archives


(Alfredo) #8

Hi agaida, thanks for the answer.

File contents are https://paste.ubuntu.com/p/2t87sXkvYF/

Regards


(Alf Gaida) #9

i suggest to do this kind of things in a more generic way - starting with

  • chosing a matching desktop file as template, a lxqt one would be fine
  • one will find all installed desktop files in /usr/share/applications
[Desktop Entry]
Type=Application
Name=About LXQt
GenericName=About LXQt
Comment=Learn more about LXQt
Exec=lxqt-about
Icon=help-about
Categories=System;Documentation;
OnlyShowIn=LXQt;

Name[ar]=عن لكسكيوت
GenericName[ar]=عن لكسكيوت
...

First 5 lines are obvious, the exec part is important, the icon is important and should be there, Categories define where/if there will be a menu/settings entry. The Show/OnlyShowIn only about visibility and the ability to run in various DEs and can be ignored if desktop agnostic. So it boils down to the Exec.

Please read the documentation available at freedesktop.org about. My guess is that a

Exec=sh -c $foo 

will do the trick.


(Alfredo) #10

Hi agaida, thanks again.

I tried your example, and open the About LXQt window ok.

Then I changed the Exec value by the path to the script (with sh -c, with sh - “…” and without sh -c) with no luck. Now a dialog opens asking Open or Execute. I click Execute but nothing happens.

alfredo@s-nm-anderson-plx:~/Desktop$ diff agaida.desktop*

6c6

< Exec=sh -c “/opt/squirrelsql/squirrelsql-3.9.1-optional/squirrel-sql.sh”


> Exec=lxqt-about

Regards


(Alf Gaida) #11

erm - to be blunt - you think that the squirrel script does nothing, thats a major difference - if it exists and terminate asap because some environmental things are not set or be not avialable in the chosen context i wouldn’t call it nothing :smile:

i would start with a simple script first:

#!/bin/bash

echo "Test Logging ..."
echo "Test write to /tmp" >> /tmp/test.txt

Started as user from the terminal

agaida@ramme ~ % bash test.sh
Test Logging ...
agaida@ramme ~ % cat /tmp/test.txt 
Test write to /tmp

Desktop file

% cat Desktop/test.desktop 
[Desktop Entry]
Type=Application
Name=Test
GenericName=Test
Comment=Test Logging and write a file
TryExec=/home/agaida/test.sh
Exec=/home/agaida/test.sh
Icon=help-about

When started via desktop file the Logging test should appear elsewhere …


(Alfredo) #12

Hi agaida, thanks for the tips!!!

It’s working now (I have to hardcode the java path because some environment variables were not set when running the script this way).

Regards, Alfredo


(Alfredo) #13

Hi guys, just for completeness sake …

Setting JAVA_HOME environment variable in Session Settings allows me to run the script without modifications.