Page 1 of 1
Forum

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 exec...
 
Share:
Notifications
Clear all

macOS - How to execute a shell script with a double click


 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 2010
Topic starter  

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.


ReplyQuote
 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 2010
Topic starter  

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.


ReplyQuote

Like what you see and you'd like to help out? 

The best way to help is of course by assisting others with their questions here in the forum, but you can also help us out in other ways:

- Do your shopping at Amazon, it will not cost you anything extra but may generate a small commission for us,
- send a cup of coffee through PayPal ($5, $10, $20, or custom amount),
- become a Patreon,
- donate BitCoin (BTC), or BitCoinCash (BCH).

Share: