14

What I want to do at all, is that: Create script that has icon on it. So I know only one way - file.desktop file with icon. Settings icon on it was successful, but I have no luck setting EXEC value :/

Can someone explain me a bit how to create executable script with icon on it? create .desktop file and link it to that script? Can someone give me structure of that .desktop file?

1

4 Answers 4

20

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
1
  • 5
    BOTH the desktop file and the script must be executable. Otherwise it didn't work for me. Commented Dec 17, 2017 at 17:06
9

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.

1
  • May need desktop-file-edit, desktop-file-install, and desktop-file-validate now. Also seems to be desktoptojson as well.
    – Pysis
    Commented Mar 2, 2022 at 20:17
1

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.

2
  • 2
    In Ubuntu 20.04.1 LTS, you will also need to add #!/bin/bash above cd "${0%/*}" in the bash script the DESKTOP file is pointing to, for it to be registered in the Activities pane. Commented Oct 7, 2020 at 15:44
  • I tried your (understandable approach), had to refine it to properly handle space-containing paths (automatically passed on in single quotes) → see here
    – Frank N
    Commented Dec 27, 2021 at 11:58
0

Make a file called testicon.desktop and place it on the desktop

$ more testicon.desktop
[Desktop Entry]
Version=1.0
Type=Application
Terminal=true
Icon=/home/robin/Desktop/testicon.png
Name=TestIcon
Exec=/home/robin/Desktop/testicon.sh
Comment=Some comment for en_GB
Name=TestIcon
Comment=Some comment.
Icon=/home/robin/Desktop/testicon.png

Here is an executable bash script. Place it on your desktop and run it and it will describe making an icon that runs a script

$ more testicon.sh
#!/bin/bash

# this forces bash to use the Desktop directory i.e. where this bash script is located
cd "${0%/*}"

echo "to make a shell script run from an icon"
echo " make a file like this "
sleep 1
echo "====================================================="
cat ./testicon.desktop
echo "====================================================="
echo "called something like testicon.desktop"
sleep 2
echo " chmod +x the .desktop file"
echo " make a png file for the icon call it testicon.png"
echo " now right click on .desktop file and allow launching"
echo "should work"
sleep 10
echo "bye, disapparing in ten seconds"
sleep 10
 NUC 2023-11-16_16:05 ~/Desktop

This works for

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.6 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.6 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

You must log in to answer this question.

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