5

Summary: How to set Run in Terminal as the default Nautilus doubleclick action?

I wish to run an interactive script by doubleclicking it. To interact with it, I have to see it run.

If I gsettings set org.gnome.nautilus.preferences executable-text-activation to ask, then it gives me a choice; Run in Terminal does what I want; Run doesn't, since when the script needs to ask me something, it just hangs. However, I don't want to have to click the Run in Terminal every time. I want it to do that by default. I've done it before somehow.

I tried to gsettings set org.gnome.nautilus.preferences executable-text-activation to launch; however, that simply does Run as the default; I don't see a way to make it Run in Terminal by default.

I have also tried inserting a gnome-terminal command. This successfully pops up a terminal window (even when simply Run); however, I then somehow need to send all the commands to that terminal window.

Alternatively, I know how to send (just) the interactive portion of the script to that terminal, which would work for me; however, in that case I need the script to halt until the interactive portion of it finishes, and then resume the execution. Typically, this can be accomplished using the wait command; as is, the gnome-terminal command seems to work as gnome-terminal& instead, in that it relinquishes control to the bash script as soon as it is launched.

I've read through almost 10 duplicates of the thread How do I run executable scripts in Nautilus? (including other sites), and still cannot find my answer. Any other workarounds will be appreciated.

Alex
  • 157

3 Answers3

4

Not literally what you asked for, still an elegant option I believe:

Add a right-click option to run a selected script in terminal

  1. Create a small script:

    #!/bin/bash
    gnome-terminal -e $1 
    
  2. Save it as run_interminal.sh in ~/.local/share/nautilus/scripts. Create the directory if it doesn't exist.

  3. Make the script executable.
  4. Log out and back in.

That's it. Select a script and choose Scripts --> runinterminal.sh:

enter image description here

Alternatively; drag/drop- run in terminal

Drag an (executable) script over a launcher to have it run in the terminal:

  1. Copy the code below into an empty file and save it on your desktop as run_script.desktop

    [Desktop Entry]
    Name=Run Script
    Type=Application
    Exec=gnome-terminal -e %u
    Terminal=true
    
  2. Make it executable

That's it. Now when dragging an executable script on to the icon, it will run in (gnome-) terminal.

Important note

As mentioned, the script run_interminal.sh needs to be executable to appear in the menu.
As it is, the script to run also needs to be executable. run_interminal.sh can easily be set to automatically make the targeted script executable or call an interpreter. If that is needed, please mention.

Jacob Vlijm
  • 85,475
1

This solution should works for every:

  • file managers that support "configurable personal actions".

  • file managers that is configured to open files with double-click.

  • x terminal emulators that has options for executing: "-e" or "--execute".

  • script that have the permission to be executable.

EDIT

Tested with thunar file manager and after that, i installed nautilus and now double-click execute script for both.

1- Right-click on your script

2- Select "open with"

3- Click "open with other application"

4- Click "open with a command"

5- Check "use this action for this kind of file"

6- Enter the following command in the text area: x-terminal-emulator -e "/bin/bash %f"

7- Click Open,your script is executed in the terminal window.

8- Restart your file manager

Now evey time you double-click on a script,it will be executed.

0

Found the short solution to the question. Adding --disable-factory to the gnome-terminal options makes it wait for the terminal to finish, before continuing the rest of the script.

Alex
  • 157