43.beta File manager's "Open With" should let you open a script with Gnome Terminal (without hacks)

How to currently achieve this:

touch ~/.local/share/applications/Terminal.desktop
nano ~/.local/share/applications/Terminal.desktop
[Desktop Entry]
Type=Application
MimeType=application/x-shellscript
Name=Gnome Terminal
Icon=org.gnome.Terminal
Exec=gnome-terminal -- bash -- %f

Often you need to make a custom script (for instance connecting via SSH to a machine). Instead of opening the terminal or writing a gnome-terminal command with executed code afterwards, why not optionally allow a script to be opened in Gnome terminal.

Not by default of course.

1 Like

You can right-click on a script, and check “Allow executing file as program”, then right-click on the file and click on the “Run as program” entry.

However, you must do this for each file (you can use selection to apply to multiple files at once).

That’s all I know. There may be other ways that I don’t know about.

Unfortunately that doesn’t open in terminal for me. It might open in the background instead.

Even creating a script with:

#!/bin/bash

gnome-terminal

And then enabling the oddly worded “Executable as Program”, nothing appears to happen. Perhaps this feature is broken in my version of Gnome if it works for you?

Yes, it works: I briefly saw gnome-terminal running the script and gnome-terminal appeared.

If you correctly wrote here what you wrote in your script, it may be due to an error: it is !#/bin/bash and not #!/bin/bash.

Sorry: I forgot to test with the development version (flatpak). I don’t have 43.beta but 44.alpha-9fdb61870, and it doesn’t work. If you used the flatpak version, I think it’s because there is no terminal/console access inside a flatpak setting.

That is wrong. It is called Shebang for a reason.

gnome-terminal only tells gnome-terminal-server to create a new window and then exits. And the terminal window opened by running the script from nautilus closes once the script finishes (depending on how you configured gnome-terminal).

Do a Google search. #! Is correct. !# makes no sense, as # tells the script interpreter (bash eg), to ignore processing this line.

Yes, I tell it to stay open. But it definitely doesn’t open in terminal unless I explicitly tell it to. “Run as a program” for some reason isn’t.

I’m using 43.beta non-flatpak. I’ve just updated from 43.beta to 43 and it doesn’t work. But at least they fixed a weird issue of multiple windows appearing upon an action.

I have to right click and “run as program” each time. Unless I explicitly make it open with gnome-terminal with the method stated in the first postm

What happens if the script you try to run is just the following?

#!/bin/sh
read

Just to make sure the script does not immediately exit.

It works for me.

Regarding the “#!” case, I was confused because I didn’t briefly see gnome-terminal running the script.

So the problem is not seeing the output?

The terminal closes when the script exits. If you want to the terminal to stay open you have to do that yourself. Like put something like this at the end of the script:

read -s -p "Press enter to close terminal..."
1 Like

So what is the goal? See output or have terminal open to type commands after script execution?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.