0

I wrote a simple script in a text file, put it on the desktop, and made it executable. When I double-click it (or right-click and "Open" it) from the desktop, nothing happens - it does not run. But when I open the "/home/username/Desktop" folder and double-click the same script from there, it runs in a terminal.

How can I allow my script to run by double-clicking it when it is on the desktop?

3
  • Is this a *.desktop file? If so gio set Desktop/your-file.desktop "metadata::trusted" yes
    – nobody
    Jan 10, 2021 at 13:13
  • Don't you get the prompt to execute the script in a terminal for example?
    – FedKad
    Jan 10, 2021 at 13:13
  • @FedonKadifeli not when I run it from the desktop. Jan 10, 2021 at 14:23

2 Answers 2

2

you have to mark the *.desktop file as trusted.

In unity I don't no graphical way.

gio set $HOME/Desktop/your-file.desktop "metadata::trusted" yes
1
  • Thanks! After doing this, I had to right-click the desktop file and choosee "Allow Launching", and then it finally worked. Jan 11, 2021 at 8:25
1

Good practice to run a script would be to place it in a folder ~/bin or a folder .local/bin under your home folder. Executables placed in one of these folders will automatically be included in your search PATH. That means that you can execute the script directly by typing its name at the terminal prompt or in the Run dialog that you get when you press Alt+F2.

If you want to be able to launch the script using your mouse, then good practice would be to create a launcher for it. Launchers you put in .local/share/applications will automatically appear in the application overview. From there, you could pin them to the Dash or the Ubuntu Dock for very quick access. Alternatively, you will be able to very quickly launch the script by hitting Super then type a few letter of the name of the script. See here (answer of fnkr) for how to create a .desktop launcher.

To run the script from the desktop, place the .desktop file in your Desktop folder. On your first attempt to launch it, you will be asked by the system for permission to run it.

3
  • I made a .desktop file, but now when I double click it, it opens in a text editor (even when I choose "open in terminal). Jan 10, 2021 at 14:23
  • This is the file I created: "#!/usr/bin/env xdg-open [Desktop Entry] Version=1.0 Type=Application Terminal=true Exec=/usr/local/bin/speedtest-cli Name=Speed Test Comment=Speed Test Icon= " Jan 10, 2021 at 14:24
  • Desktop file needs to be placed on the desktop and probably right-clicked to allow execution (sorry, I do not use the Desktop Icons extension myself, so I am not aware of the details).
    – vanadium
    Jan 11, 2021 at 9:18

You must log in to answer this question.

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