Score:1

Launch script with double click don't work

it flag

I'm trying to launch a bash with a double click on it.

I made a simple script :

#!/usr/bin/env bash
echo Hello, who am I talking to?
read varname
echo "It's nice to meet you" $varname

and I also tried by putting #!/bin/bash but didn't change

I did

sudo chmod +x script_name 
dconf-editor

and set launch file on click in dconf-editor.

I also tried to add .sh extention to the file without success.

With all of this, the file is not running when i double click on it. I'm using ubuntu 20.04, and I didn't find any helpfull post about this problem. Maybe I didn't searched well or enough so feel free to send me

Additionnal intels :

  • The script work well when I launch it from terminal,
  • When I set "ask" in dconf-editor is ask me how I want to open it, but launch still don't work.
  • Using the "ask" option, and then click on "run in terminal" make it work. But I want it to work without the ask window, to make it more user friendly.
  • The post Bash script using `sudo` runs correctly from cli but not when clicked to run is not helping me since I don't have sudo commands inside my script.

expected behaviour: A terminal is open saying "who am I talking about?"

Thanks a lot. And sry about my english level I'm not native. Bouq

Score:3
cn flag

Some will say: "move to another desktop environment".

In the Gnome desktop environment, used by Ubuntu, the ability to run any program by double-clicking on it in the file manager is deprecated. It is indeed handy in some use cases. In other use cases, it can be confusing for users and for sure, it can be a security nightmare. Which is probably an important reason why it is deprecated.

It actually remains possible to set that up, however, it is not anymore set up by default.

  • If you are a developer needing to run an application during development, open a terminal. Enter the name of the program once (use Tab for command completion. Then use arrow up to repeat the command.
  • If you are an end user needing to run some application, then install it properly. Install or link the executable in your ~/bin or ~/.local/bin directory. Run it from the terminal just by typing the name, or create a launcher to it in ~/.local/share/applications. Then, you can run it from the application overview, and even pin it to the dock for quick access.

Still, you could set up the ability to run files from the file manager by setting up a .desktop launcher that runs a file you provided as an argument. A .desktop launcher with the line Exec=gnome-terminal -- %f would open Gnome Terminal and (try to) run the file name provided, represented by the %f. If it is a script, you will see it running in the terminal. If it is a graphical application, Gnome terminal will briefly load, but disappear once the graphical application has started. A minimal .desktop launcher for this is:

[Desktop Entry]
Name=Generic application runner
Comment=Runs executable files
Exec=gnome-terminal -- %f
Type=Application    

With the .desktop file installed in ~/.local/share/applications, you can run any program by right-clicking and selecting "Open with...". You can associate files with a specific extension, e.g. .sh for scripts, to that launcher so it runs upon double click.

Alternatively, you will need to at least switch to a file manager still supporting the feature, or switch to another desktop environmemt like Mate or Xfce.

Hedwin Bonnavaud avatar
it flag
Thank you for this complete explanation, I better understand how all of this can work and why it's deprecated, thanks a lot. Actually I will choose the clean way, create an app.
vanadium avatar
cn flag
Good, although I did some painful testing to have my .desktop launcher work ;) You need to log out then back in to have it appear in the "Open with" dialog.
Hedwin Bonnavaud avatar
it flag
Ok, thank you !
Matthew T Wetzel avatar
cn flag
seems somewhat silly for gnome to deprecate that functionality. they still allow you to "Right click -> Run as program", so clearly the functionality is popular enough to warrant just running on double click automatically
Score:0
pe flag

There're many ways to solve your problem.

Desktop application

You can create a files with name and directory ~/.local/share/applications/abc.desktop

[Desktop Entry]
Type=Application
Terminal=true
Name=Click-Script
Icon=</path/>
Exec=gnome-terminal -e "bash -c './script.sh;$SHELL'"
Categories=Application;

Update preferences of Nautilus

Open Files (maybe it's called Nautilus) -> Perferences -> Behavior

Select Ask what to do

ChanganAuto avatar
us flag
The second option is no longer available in 21.10 (with Gnome 40).
Hedwin Bonnavaud avatar
it flag
Didn't test the first option yet, but the second don't work, it is part of what I tried: `I set "ask" in dconf-editor` which also change this configuration in nautilus preferences also. It's the same setting. Btw, ty for your help ! :)
Score:0
nl flag

These script are considered executables, so you can invoke only from a environment. (Unless you need to edit them).

i did these task with this method (on KDE plasma environment)

  1. Create a .desktop file in your desktop with this content

[Desktop Entry]
Comment=link to my script
Exec=/path/to/your/script
GenericName=
Icon=system-run
Name=link to my script
StartupNotify=true
Terminal=true
TerminalOptions=
Type=Application

  1. Save it and Perform a "double click" over for lastly show the magic !

Note
The option "Terminal=true".
and you can invoke your task in a terminal window.

Note 2
obiously you can set "Always ask" in the "on open excecutable files" option in Dolphin ( Ctrl + shift + , )

Score:0
mm flag

In Ubuntu 22.04 I right mouse click then "run as program", this is not much more trouoble than doubleclick but I keep forgetting. When I doubleclick it opens the editor.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.