Execute sh script from *.desktop file?

You didn't mention what you have tried, so try this:

[Desktop Entry]
Name=someName
Comment=
Exec=/path/to/script.sh
Icon=/path/to/icon
Terminal=false
Type=Application  

Make sure that your script is executable, like this:

sudo chmod +x /path/to/script.sh  

It also won't work with if your script uses the sudo command, or anything else that requires user input.

If you want it to open a terminal window when you run it (if you needed to add input or watch the output) set Terminal to true.

Terminal=true

Use gnome-desktop-item-edit :

gnome-desktop-item-edit --create-new /path/to/new/launcher

# Usually, one does (create launcher in current directory) :
gnome-desktop-item-edit --create-new .

You'll be graphically prompted for those settings. Here's one of my launcher, which I created with this tool :

#!/usr/bin/env xdg-open

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon[en_GB]=/path/to/icon/for/en_GB.png
Name[en_GB]=Name_for_en_GB
Exec=/path/to/shell/script.sh
Comment[en_GB]=Some comment for en_GB
Name=Launcher Name
Comment=Some comment.
Icon=/path/to/icon/file.png

The en_GB specific settings are not mandatory. Feel free to fill in with identical values.


Make sure the first command of the bash script is cd "${0%/*}" if nothing appears: this command changes the current working dir into the directory containing the script as most shell scripts work with relative paths starting from their dir.