36

I have just created a .desktop shortcut on my desktop to launch a shell scrip. The script itself works fine, but its shortcut that doesn't display the icon and double-clicking on it just displays its content in gedit:

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/home/alvaro/Desktop/Laptop_screen_config.sh
Name=Screen_config
Icon=/home/alvaro/Desktop/Ubuntu/screen.png

It is allowed to execute as a program in its permissions, so that's not an issue:

File permissions

Does anyone have any ideas why this is happening? Any help would be greatly appreciated!

Lorenz Keel
  • 8,905
Alvaro
  • 363
  • Create a folder on your Desktop called TEST, or whatever. If you move the .desktop file into that TEST folder, does it work then? – heynnema May 08 '20 at 14:41
  • No, same behaviour inside a folder – Alvaro May 08 '20 at 15:05
  • Move your .desktop file into ~/.local/share/applications/, then hit the Super key and type the name of the shortcut, and see if it works then. If not, move the .sh file into your Documents folder, edit the .desktop file, and retry. Make sure the .sh file is executable. (.desktop files, and files on the Desktop, work strangely in 19.xx and higher). – heynnema May 08 '20 at 15:12
  • Thanks for the answer, that way the .desktop file can run (still doesn't display the icon though). However, the point was to have a shortcut in the desktop, can't believe this is so difficult – Alvaro May 08 '20 at 15:29
  • You've given terminal false, So the script might have executed and completed. Is it throwing any error by the way? – Jijo Joseph Dec 02 '20 at 17:22
  • I figured it out: Just open the file with your browser as a standard setting (it does work with firefox, haven't tested others). You don't have the beautiful icon, but it works. – user510186 Feb 03 '21 at 05:10

13 Answers13

30

Make sure you've allowed launching and, maybe, selected it as Run Software on Open With tab.

enter image description here

Configure your shortcut the next way:

[Desktop Entry]
Version=1.0
Name=Firefox Web Browser
Comment=Browse the World Wide Web
GenericName=Web Browser
Keywords=Internet;WWW;Browser;Web;Explorer
Exec=/home/alvaro/Desktop/Laptop_screen_config.sh
Terminal=false
X-MultipleArgs=false
Type=Application
Icon=/home/alvaro/Desktop/Ubuntu/screen.png
Categories=GNOME;GTK;Network;WebBrowser;
MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/rss+xml;application/rdf+xml;image/gif;image/jpeg;image/png;x-scheme-handler/http;x-scheme-handler/https;x-scheme-handler/ftp;x-scheme-handler/chrome;video/webm;application/x-xpinstall;
StartupNotify=true
Actions=new-window;new-private-window;

I've copied firefox's shortcut settings and modified them to allow to launch your script. With this it allows changing its launching configuration. You could remove unneeded options and check if it works without them.

Gryu
  • 7,559
  • 9
  • 33
  • 52
  • 11
    I have tried to set "Run Software" as the default application with the same result and unfortunately I don't have the option "Allow launching" when I do right clic on it... – Alvaro May 08 '20 at 14:52
  • I have used your proposal using the firefox config but same behaviour. When I open it from the desktop it just opens the file and if I open it from nautilus (having allowed to run it in preferences/behaviour) it just open the terminal briefly but doesn't run the script. – Alvaro May 08 '20 at 15:13
  • I have tried exactly your config but unfortunately I don't have the Allow launching option when I do right click on it... any idea why this could be? – Alvaro May 08 '20 at 15:21
  • @Alvaro consider using Gnome desktop instead of Unity. As it seems, Unity does not have this ability. Make a screenshot of your desktop with launcher visible to see what it should be. – Gryu May 19 '20 at 10:14
  • Do you know what happens behind the scenes if you click "Allow Launching"? I'm guessing it doesn't just set the executable bit. – Flimm Nov 24 '23 at 12:51
19
  • Move the .desktop file into ~/.local/share/applications/ and make executable if need be.

  • Move the .sh and .png files into ~/Documents and make sure the .sh is executable.

  • Modify your .desktop file for the new locations for the .sh and .png files.

  • Hit the Super key and type the name of your shortcut.

  • You can save your .desktop file as a favorite in the Dock for quick access.

Enjoy!

heynnema
  • 70,711
  • 5
    This option has worked for me but the point was to have the shortcut on the desktop which seems to be the real issue – Alvaro May 08 '20 at 15:49
  • 3
    @Alvaro As far as I know, .desktop files won't work from the Desktop in 20.04. – heynnema May 30 '20 at 16:57
16

This was hidden in the comments but it is absolutely the only way to make it work on Ubuntu 20.04 LTS after the latest updates:

This still works (going back several Ubuntu versions):

Copy the application launcher in your home directory (~/application.desktop)

At the command line (in a terminal) run sudo desktop-file-install application.desktop.

This checks the syntax of the launcher and (if it has no errors) installs it into /usr/share/applications.

Open nautilus in /usr/share/applications.

Find the icon for the launcher (application.desktop) and drag the icon to some convenient location in the dash. This locks the launcher to the dash.

  • 3
    This is a good first answer but could use some formatting. eg use sudo desktop-file-install application.desktop instead of "sudo desktop-file-install application.desktop". More importantly though a few screen shots would make the answer easier for people to try out on their own machines. – WinEunuuchs2Unix Dec 31 '20 at 22:10
  • 2
    desktop-file-install also validates the .desktop file which is really important to catch potential errors/issues. desktop-file-validate is the dedicated command for validation. – Junaid Mar 06 '21 at 21:28
  • Drag&Drop in nautilus fails for me because of permission issues, what works is copying it on command line. – Marc Johnen Apr 09 '21 at 11:38
  • This is great but I have a blank icon on my dock... any way to put any kind of icon? – BrianBlaze Dec 29 '21 at 18:25
  • @Junaid, Thank you so much for the validation. That helped me big time. Turns out the "Version" key is NOT mandatory and it is NOT referring to the version of the application the shortcut is pointing to. I set it to 1.0, which was valid. See the docs at Open Desktop org: https://specifications.freedesktop.org/desktop-entry-spec/latest/index.html Also upvoted you, of course. – George Smith Oct 08 '22 at 16:34
  • @GeorgeSmith glad it helped you :) – Junaid Oct 08 '22 at 22:32
8

I had the same issue and I was struggling for quite while

Issues that I was facing:

  1. Icons were not showing
  2. Double Clicking an a desktop shortcut would open a text editor instead of launching the application

How I solved this problem?

Right click the icon > Properties > Permissions

Set Group access to Read and Write and Others Access to Read-only and check Execute.

Shortcut Icon permission settings

and select Allow Launching

Allow Launching

Now You icon will appear and you can double click to run the program

enter image description here

Ashish
  • 201
  • Nicely explained with the images. – PhoneixS Oct 01 '20 at 08:53
  • 4
    Setting the access for others to "Read-Only" seems to be the key for the "Allow Launching"-menu option even showing. That's the piece of the puzzle that was missing from the other answers. I would be interested in their reason for hiding the option and making the transition seemingly as convoluted as possible. At any rate: +1 – Kakturus Jan 28 '21 at 13:11
7

How I solved it. None of these tips worked for me, yet I had a manually created shortcut to Spyder on my desktop that worked. Like many of you, "Allow Launching" did not appear in the right-click context menus. My problem was in the EXEC= field, and that I used the ~ character rather than the real path.

  • I experienced the same. In any of the field that takes a path, the tilde (~) character could not be replaced with current user's home directory path. And giving an absolute path (without the ~ character) works. Then the xyz.desktop file can be copied to home or any other directory. Right click on it and then "Allow Launching" would appear in the context menu. Click on this option and the launcher works! – soupso Mar 21 '23 at 10:41
5

None of the above worked for me.

This still works (going back several Ubuntu versions):

  1. Copy the application launcher in your home directory (~/application.desktop)
  2. At the command line (in a terminal) run "sudo desktop-file-install application.desktop" (without the quotes). This checks the syntax of the launcher and (if it has no errors) installs it into /usr/share/applications
  3. Open nautilus in /usr/share/applications.
  4. Find the icon for the launcher (application.desktop) and drag the icon to some convenient location in the dash. This locks the launcher to the dash.
3

First, set the .desktop file as 'trusted':

$ gio set <entry.desktop> metadata::trusted true

Then:

$ sudo chmod +x <entry.desktop>
1

My final solution (after fixing permissions, ownership, typos, etc..) was to make a copy of the launcher from the desktop back on to the desktop. No other changes. The copy (which had identical ownership and permissions) had the "Allow Launching" context menu item; the original did not.

  • Similar experience. Currently I'm able to go to terminal and run cp myprogram.desktop myprogram2.desktop, and then the original one (myprogram.desktop) starts working again, as well as the new one having "Allow Launching". Then it fails again after like 1 day and I can repeat the same process to get it to work again... – krubo Sep 04 '21 at 19:32
1

The Allow Launching was not appearing for me at all. There is subtle but important point made by Kakturus above. I am re-stating it below. The access for others needs to be Read-only, then the Allow Launching will appear!

Setting the access for others to "Read-Only" seems to be the key for the "Allow Launching"-menu option even showing. That's the piece of the puzzle that was missing from the other answers. I would be interested in their reason for hiding the option and making the transition seemingly as convoluted as possible. At any rate: +1 – Kakturus Jan 28 at 13:11

1

Just type on terminal, at the path where the .desktop is located "chmod -R 755 ."(as . is making reference to the path where you are at the moment of typing), advice, do it on /Desktop to make sure futures icons will get those permissions. Take care

0

Sorry if this method doesn't work for you. In properties box of the file you must change Others access to Read only to see the Allow launching in the dropdown menu. May it help.

thong
  • 1
0

I've the same problem but my starter is created by a bash script that installs an application. The starters is created but is not launchable with Ubuntu 20.04 (it works fine with 18.04). So, is there any command such as "chmod" to include in my script and to apply to the starter file that makes it "launchable"? BTW, on Ubunru 20.04, this problem occurs only with Gnome and not with both Cinnamon and Mate!!! Thank you in advance.

Fnux
  • 151
  • As you already know about Cinnamon and MATE, then maybe it is time to switch to one of them? – N0rbert Mar 07 '21 at 07:22
  • Sure, but since my script installs an application, I'd like to make it running the same way whatever GUI the user runs (Cinnamon, Mate, Lxde... AND Gnome 3) on its system. So, I'm looking for the command that the Gnome 3 GUI uses to make a starter launchable when you use the GUI menu option as described below by Gyru and Ashish. I bet it's not a secret but I didn't find any documentation on this subject yet. – Fnux Mar 07 '21 at 22:28
0

Had the same issue when after installing JetBrains Toolbox and IDEs on Ubuntu 23.10.

For me, the error was executing the toolbox install script using sudo which is not recommended. As a result, the application and .desktop files were installed in /root/.local/share instead of in ~/.local/share and the programs would not show in the application launcher.

Fixed the issue by deleting /root/.local/share/JetBrains and the false /root/.local/share/applications/*.desktop files and install the Toolbox and IDEs again without using sudo