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?

2 Answers2

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
nobody
  • 5,437
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.

vanadium
  • 88,010
  • 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). – Erel Segal-Halevi Jan 10 '21 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= "

    – Erel Segal-Halevi Jan 10 '21 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 '21 at 09:18