Run script from Nautilus without opening terminal

Solution 1:

In response to the issue 'Executable Text Files preference considered unhelpful' on gitlab, the option to ask what to do when double clicking an executable has been removed from the GUI and took running a program without a terminal with it.

There are two ways that I know of to achieve this


1- Create a nautilus script that runs an executable in the background then closes it's own terminal:

put a shell script in ~/.local/share/nautilus/scripts/ and mark it as an executable so it shows in the context menu under the Scripts sub-menu and write these commands inside it:

#!/bin/sh
nohup "./$1" >/dev/null 2>&1 &

You can refer to this answer on a question for some explanation regarding nohup and disown. (another way to detach a process) However do note that processes detached in this way won't automatically close when you logout of your user

You can also just use sh -c './$1 &' instead of the whole nohup nuisance as noted by a comment on the same question.

2- Use the deprecated filemanager-actions to add an option to the context menu to run an executable without a terminal:

  1. sudo apt-get install filemanager-actions
  2. either run it using the launcher or run it's binary directly from the terminal fma-config-tool
  3. if you don't want your custom context menu options to be inside a sub-menu go to Edit->Preferences->uncheck Create a root 'FileManager-Actions' menu
  4. now add a new action. name it whatever you want, this name will be shown in the context menu.
  5. go to the Action tab and make sure the Nautilus item section is checked for selection and unchecked for location as in this screenshot
  6. go to the Command tab and set the path to %f it should look like this
  7. go to the Execution tab and make sure the execution mode is set to normal. this allows for execution in a hidden terminal. screenshot
  8. go to the Capabilities tab and add the Executable filter then check the Must match all of option for that filter. screenshot
  9. now save (right next to where you added the action) for the changes to take effect. and now you'll see your option added to the context menu for files with the executable bit set like in this screenshot (in my case i named it run in background)

NOTE: You can use the same commands used in the script in filemanager-actions. You just need to set the command (screenshot) to

/bin/sh

and it's parameters to

-c 'nohup "%f" >/dev/null 2>&1 &'