11

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?

Erikas
  • 621
  • 1
  • 7
  • 13
  • 1
    possible duplicate of [Apply icons to bash scripts](http://askubuntu.com/questions/60667/apply-icons-to-bash-scripts) – bain May 23 '14 at 11:59

3 Answers3

16

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
Radu Rădeanu
  • 166,822
  • 48
  • 327
  • 400
Seth
  • 57,282
  • 43
  • 144
  • 200
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.

John WH Smith
  • 2,018
  • 14
  • 21
  • May need `desktop-file-edit`, `desktop-file-install`, and `desktop-file-validate` now. Also seems to be `desktoptojson` as well. – Pysis Mar 02 '22 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.

Zac
  • 201
  • 3
  • 12
  • 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. – tom_mai78101 Oct 07 '20 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](https://askubuntu.com/a/1383967) – Frank N Dec 27 '21 at 11:58