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

[Solved] macOS - How to execute a shell script with a double click

2 Posts
1 Users
0 Reactions
11.5 K Views
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2741
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)
Famed Member Admin
Joined: 11 years ago
Posts: 2741
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
Share: