Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
macOS - How to execute a shell script with a double click
March 13, 2021 4:35 AM
It doesn't happen often, but sometimes you have a little shell script which you'd like to run by double clicking it for example from the desktop.
Most of use use the extension ".sh" for a shell script, but this could be associated with a text editor like BBEdit (highly recommended and there is a free version). So instead of running the script, it will open it in your text editor. Bummer ...
I did find an easy fix: change the extension to ".command" and make the file executable.
For example; let's say I created myscript.sh then rename it to myscript.command and use chmod to make it executable (in Terminal):
chmod +x myscript.command
You can now double click the script and it will be executed.
June 21, 2021 5:24 AM
As an alternative, you could change the file association:
Right click a ".sh" file and select "Get Info".
Scroll down to the "Open With" section and set it to Terminal.
Now Terminal may not be listed as an option, so in that case select "Other..." from the menu and browse to Terminal (found in Applications - Utilities).
Next click the "Change All" button, and as of now each ".sh" file will be opened with Terminal and a the script will be executed.