How Do I Get Finder to Execute a Bash Script?

Joined
Apr 29, 2006
Messages
4,576
Reaction score
378
Points
83
Location
St. Somewhere
Your Mac's Specs
Mac Studio, M1 Max, 32 GB RAM, 2 TB SSD
I have created a shell script that I would ideally like to have Finder cause to execute when I double click on it. I created the script, changed its permissions so that it was executable, and then tested it from within Terminal.app. It works fine there. However, when I simply double click on the file from within a Finder window, it treats it like a text file and opens it in TextEdit.app. How can I make it execute the file instead? Thanks!
 

rman


Retired Staff
Joined
Dec 24, 2002
Messages
12,637
Reaction score
168
Points
63
Location
Los Angeles, California
Your Mac's Specs
14in MacBook Pro M1 Max 32GB 2TB
Here is my guess. You may need to add an extention to the file you created. Something along the lines of .app. I hope it is that simple.
 
OP
mac57
Joined
Apr 29, 2006
Messages
4,576
Reaction score
378
Points
83
Location
St. Somewhere
Your Mac's Specs
Mac Studio, M1 Max, 32 GB RAM, 2 TB SSD
Hey rman, I managed to solve this one myself! I had tried the .app idea as well, thinking "well, everything else is simple on the Mac, perhaps this is the way" but it didn't work.

Here is what I did. The script in question launches an X11 based program with a unique parameter set. So I did a Get Info on the script's file and changed its "Opens With" entry to "X11.app". It worked perfectly!

This isn't a general solution to getting Finder to execute a bash script, but it worked in this instance, and for now, I am happy with that. I would like a more general solution long term, but for now, I have accomplished what I need to.

Thanks for the help though!
 
Joined
Jun 25, 2005
Messages
3,231
Reaction score
112
Points
63
Location
On the road
Your Mac's Specs
2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
Perhaps you created the script using TextEdit? If so, the creator flag is set to TextEdit and it will open it. This would suggest that you could change it by opening the Info panel and associating the script with say, the Terminal app.

Via the Finder, use the Go option to open the /bin directory. Take a look at the Info panel for the ls command. Copy the idea.
 
Joined
Aug 27, 2005
Messages
2,406
Reaction score
210
Points
63
Location
Fayetteville, AR
Your Mac's Specs
15" Powerbook G4 • 24" iMac • iPhone 3Gs
xStep may be right, you may want to use pico or nano in Terminal and just write out from there.
 
OP
mac57
Joined
Apr 29, 2006
Messages
4,576
Reaction score
378
Points
83
Location
St. Somewhere
Your Mac's Specs
Mac Studio, M1 Max, 32 GB RAM, 2 TB SSD
xstep, that sounded promising, but when I attempted it, with the Get Info panel, to set the "Opens With" to Terminal.app, it wouldn't let me. Terminal.app was grayed out and not selectable. Darn!
 
Joined
Sep 21, 2005
Messages
809
Reaction score
111
Points
43
Location
ohio
Your Mac's Specs
iBook G4 OSX Tiger
mac57 said:
xstep, that sounded promising, but when I attempted it, with the Get Info panel, to set the "Opens With" to Terminal.app, it wouldn't let me. Terminal.app was grayed out and not selectable. Darn!
try changing it from Recommended Apps to All apps at the top of the Opens With dialog and see if it works

Picture 1.png
 
Joined
Feb 14, 2004
Messages
4,781
Reaction score
166
Points
63
Location
Groves, Texas
Give the script the extension .term
When you double click it, it should open terminal and run.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top