i have this bash script: test.sh that i would like to be able to find in my apps and/or as a favorite in my dock.

since i've never done that i relied on: Execute sh script from *.desktop file?

i then created a file: test.desktop

[Desktop Entry]
Comment=bash copy/resize
Exec=bash ~/mybash/test.sh

set permission to execute, and created /usr/share/applications, /usr/share/pixmaps and /mybash in my home directory to start with. I could right click it and run as application, but it was not visible in settings>applications

dragging it to the desktop didn't help, so found: Cannot launch .desktop files (opens with Text Editor instead)

since i did not know how to find the /.local folder i decided to copy the file:

sudo cp ~/usr/share/applications/test.desktop ~/.local/share/applications

It now can be found under settings>applications alas it is listed without the icon but i cannot find it under apps. If i search in the app view (9 dots) i find the /.local/share/applications/test.desktop listed as a text file and right clicking does not give me the option to set it to favorites and left it opens in geany (as it was made with that app)

if i try in a terminal:

bash ~/.local/share/applications/test.desktop

it starts the sh script, output in terminal:

/home/maarten/.local/share/applications/test.desktop: 1: [Desktop: not found
/home/maarten/.local/share/applications/test.desktop: 3: Cam: not found
starting gui...

and that does it's job, in the dock I see the icon I choose and a dot that it's active and the gui opens. so except for the icon location in settings>applications this part works. But double clicking still leads to the text editor. If placed on the desktop i can set 'allow launching' changing the file icon to a text document, but then double click does nothing.

the big question is Who can fill me in on what i missed in making this work?

At this moment i've copied test.desktop to:

(home)/test.desktop, (with/without allow launching)
/.local/share/applications/test.desktop and 

on all placed i can use a rightclick and choose to run as program, but nowhere does a double click lead to opening the file.

  • You said: "if i try in a terminal: bash ~/.local/share/applications/test.desktop, it starts the sh script and that does it's job. I do not believe that that worked with the file you provided. Please check and correct the information.
    – vanadium
    Apr 8, 2022 at 14:22
  • i just tried again and it might not be perfect:
    – user74341
    Apr 8, 2022 at 14:57

2 Answers 2



Try the steps below

  1. Change your .desktop file by replacing ~/some/path/file.ext to /home/<username>/some/path/file.ext

  2. You can also set Terminal=True to open a terminal when running the .desktop shortcut.

    Your .desktop file should look like this:

    [Desktop Entry]
    Comment=bash copy/resize
    Exec=bash /home/<your-username>/mybash/test.sh

Expected Behavior w/ Screenshots

  • When viewing .desktop files in a File browser like Nautilus, the files will appear like typical text files or potentially with gear symbols on them enter image description here

  • When double-clicking on a .desktop file the default file action set for that mime-type in xdg-settings will be applied, in this case the .desktop file will open in your default text-editor enter image description here
      you can check your xdg-mime settings like this: enter image description here

    As you can see, my default is GNOME Builder too


  • I've been showing the above using the JetBrains CLion IDE .desktop file, now let me show you how to properly utilize the .desktop file.
    1. first access your application menu with Super/Win key on your keyboard, or by clicking on the 3x3 grid icon on your taskbar [note: this can differ depending on your desktop environment and your configuration] enter image description here

    2. start typing your application name; in your case TEST but in my example CLion enter image description here


  1. it's already been pointed out that using the ~ shortcut doesn't work inside a Unity Launcher .desktop file

    which is why you need to specify the full path to your script and its icon file

  2. you should use either /home/<username>/.local/share/applications/ for just your user account to see the entry
    or /usr/local/share/applications/ for all users of the machine to see the entry

  3. you don't need a $HOME/usr/ folder, $HOME/.local/ is probably what you were thinking of

  4. refer here for more details about how to properly setup a .desktop launcher file


Unity Launcher Specification
Ubuntu-desktop command manual

  • Thanks, that at least got rid of the '~' but still, a double click opens the file in the editor. only right click and 'run as program' or via terminal with bash
    – user74341
    Apr 8, 2022 at 16:47
  • yes thank you, after doing that, when placed on the desktop and 'allow launching' is activated it will double click, maybe you can add that to your answer
    – user74341
    Apr 8, 2022 at 16:51
  • if the program is active, i have the icon in my dock, but on the desktop it looks like a text file, do you know the solution for that one too?
    – user74341
    Apr 8, 2022 at 16:54
  • the double click opening in a text editor is standard expected behavior. these files are meant to show up in your Application menu when you click on your keyboards Super / Win key or when you search for an application in your Activities Overview
    – wsmyth
    Apr 8, 2022 at 16:54
  • typically it showing as a text file means you need to set the .desktop file's executable bit using chmod +x filename.desktop. Or right-clicking with your mouse and setting permissions through the GUI.
    – wsmyth
    Apr 8, 2022 at 16:55

It works if the desktop file is located in the home folder. The options 'set to favorites' appears.

There is also useful application called 'menulibre'.

  • i copied test.desktop to the home folder, no option set to favorites appears. installed menulibre, but am unsure what to do with it.
    – user74341
    Apr 8, 2022 at 15:56
  • First sentence definitely is a wrong answer. Suggestion on second line might not work here if the desktop file is already valid to start with. Did you test anything?
    – vanadium
    Apr 8, 2022 at 16:12
  • if i open a winndow and go to home i see desktop, downloads, etc at the end there is one file: test.desktop, if i right click that i see: open with, run as program, cut, copy, move to, copy to, move to trash, rename, compress, send to, star, properties...where can i find set to favorites?
    – user74341
    Apr 8, 2022 at 16:23
  • and i tested what you see at the beginning and some more, but i do not really know what i'm doing (wrong) so it's hard to come up with a test.
    – user74341
    Apr 8, 2022 at 16:26

You must log in to answer this question.

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