Score:3

Can't run shell script by double click in Files (Ubuntu 21.10)

in flag

Previously in Nautilus, the problem was solved like this: How do I run executable scripts in Nautilus?

Now there is no such section and org.gnome.nautilus.executable-text-activation also does'nt work.

N0rbert avatar
zw flag
Probably it is time to try Caja or Nemo.
Score:2
cn flag

This answer may disappoint you, but here it is. Since many years, Nautilus developers are deprecating the option to run executable all over the place by double clicking on them.

One of the arguments is that executables must be curated. They should be run by users that know what they do. Else, they should be properly installed on conventional locations if they are to be run by the general users of the system.

A developer will test his executables from a terminal. A user should never be confronted with the risk of starting some - potentially malicious - process by double clicking a file somewhere in his file system. I think that is an important consideration why this option was deprecated, and now with Files 40, has been effectively removed.

This is how you should go about this:

Executables for regular use

  • Place your shell scripts in a folder ~/.local/share/bin or ~/bin. Any of these two folders will automatically be included in your search PATH —the variable that tells the system where to look for executables when you type their name at the prompt.
  • Execute your shellscript by typing its name in the terminal or in the Run dialog (Alt+F2).
  • Optionally include the script in your application overview by creating a .desktop launcher for it in ~/.local/share/applications.

Ad-hoc execution of executables for those users who know what they do

For quick running, open a terminal in the current directory ("Open terminal here" in the file manager), and run it specifying the current directory, e.g.

./myscript

For example, power users compiling software do this all the time. They move into the directory containing the configuration script, and execute it as:

./configure
Summer-Sky avatar
us flag
yes, I do not like this answer ;)
Igb avatar
in flag
Igb
Thank you very much for your answer, I do not like it either, but It was really helpful after good 15 minutes of me feeling dumb. God, this is SOOOOO Linux it hurts. There is 800 ways to do a single thing, all of them equally "hacky", 799 of them are version/environment dependent, and the only single one left gets deprecated for a good but quite debatable reason with no proper documentation to the final users. Even if Windows and Mac OS suck (they indeed do) this is terrorism to the user, no wonder every year is "the year of Linux in desktop (now for sure, finally, for real)".
vanadium avatar
cn flag
This is no terrorism to the user. There is good argument not to have casual users run anything by clicking anything in their file system. It is not because Windows 3.1 instated this that Linux desktops should continue to support this bad practice.
Score:0
cn flag

There's a workaround for this:

  1. In ~/.local/share/applications create a script that will run the parameter passed via command line:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import sys
    
if __name__ == "__main__":
    for script in sys.argv[1:]:
        if os.access(script, os.X_OK):
            os.system(f"'{script}'")
  1. In the same dir, create a .desktop file for the script:
[Desktop Entry]
Type=Application
Terminal=false
Name=Run script
Exec=/home/username/.local/share/applications/run_script.py %U
  1. Restart (in my case it was necessary) and assign "Run script" as a default application for .sh, .py, etc.
Summer-Sky avatar
us flag
thanks for the "workaround", however it shouldn't be necessary, as it isn't the place of nautilus developers to decide for the user which files to run! But they also decided to have no sorting in their over-engineered search. So basically it needs to be forked!
Summer-Sky avatar
us flag
for future reference you can also use a shell script with `cd $(dirname $@); $@` and `/bin/bash -c "${HOME}/.local/share/applications/runscript.sh %f"` as the exec. you should cd to the directory in case the script you want to run does not take care of that.
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.