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.

9
  • Simply change your script to use zenity or yad to prompt in GUI format. If you are unsure post your script contents in a "how do I"... question and some one will modify it for you in an answer. Mar 31, 2017 at 17:11
  • Can't do that... the interactive portion involves a LaTeX compiler-- so any output errors get output to the command line, and can't be routed to zenity. Don't have yad on my system.
    – Alex
    Mar 31, 2017 at 17:15
  • @WinEunuuchs2Unix Zenity isn't always the solution. Nor is a GUI. There are sometimes very good reasons to keep things in a console.
    – Kaz Wolfe
    Mar 31, 2017 at 17:26
  • @KazWolfe At this point, though, I'd be willing to accept even a not-so-good solution (that doesn't involve having multiple script files)-- but haven't found one yet.
    – Alex
    Mar 31, 2017 at 17:42
  • You can redirect LaTex errors to a file and call gedit to display the file when the compiler is finished. Mar 31, 2017 at 19:39

3 Answers 3

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.

4
  • EDIT: See comment below.
    – Alex
    Mar 31, 2017 at 18:10
  • @Alex did you log out/in and is the script run.sh executable? I assume the latter is the issue. Mar 31, 2017 at 18:11
  • Missed the logout/login part of it. Thanks, this worked!
    – Alex
    Mar 31, 2017 at 18:13
  • @Alex Ah, great :) Mar 31, 2017 at 18:16
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.

13
  • I had tried that before posting... there is no option to click "open with a command"(4). I'd even gone into Nautilus settings-- the option to "Add another application to the list" is grayed out. I suspect I need to do sudo Naulilus in order to add an application to the list-- but this fails with dconf-shm.c:92:dconf_shm_open: assertiion failed: (memory != MAP_FAILED). Any way to go around this? Maybe add this application via command line?
    – Alex
    Mar 31, 2017 at 17:34
  • i haven't done anything to nautilus,just double-click,it just works after configuring thunar,some data had been shared,because now nautilus is configured like thunar.Strange but true.
    – user-707
    Mar 31, 2017 at 17:42
  • See my edit above.
    – user-707
    Mar 31, 2017 at 17:45
  • As I said, I'd be willing to accept this answer if it works-- but there is no option for me to add a new command to the existing list of commands: Abiword, Archive Manager, Document Viewer, File, GEdit, Gnash SWF Viewer, GNU IMP, Gnumeric, Image Viewer, Movie Player, Web I don't have Thunar installed. Are there other file managers that I should try? Or other ways to get this in the list, or somehow unblocking Nautlius?
    – Alex
    Mar 31, 2017 at 17:45
  • You don't want to install thunar?
    – user-707
    Mar 31, 2017 at 17:48
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.

1
  • You need one more parameter --disable-fedora and then come join us in UbuntuLand :) Apr 1, 2017 at 1:17

You must log in to answer this question.

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