jamesatha
jamesatha

Reputation: 7600

Making an executable bash file run when clicked

I have a bash file that does some file manipulation. I don't want to have to open the terminal every time I run it. Is there a way to make the program run when I double click it? (Like a windows .exe file)

Thanks

Upvotes: 17

Views: 33016

Answers (4)

Nina
Nina

Reputation: 79

The easiest thing to do is to type: sudo chmod 755 the_file_Name.This will allow you to double click on the file in the finder.

Upvotes: 7

Gordon Davisson
Gordon Davisson

Reputation: 125708

You can add a ".command" extension to the filename -- then double-clicking it will automatically open Terminal and run the script in a new window. Note: this assumes you still want to watch/interact with the script via a Terminal interface; if you want to avoid this as well, wrapping the script with Platypus, AppleScript, or Automator (as Zifei and Ned suggest) would be better options.

Upvotes: 23

Ned Deily
Ned Deily

Reputation: 85025

With OS X 10.5+, you can wrap the bash shell script in an AppleScript application using the AppleScript editor or an Automator application using Automator.app (see the Automator on-line help).

You could write (and there are apps out there that do this) an OS X app that accepts arbitrary .sh files and executes them. However, that's generally a bad idea as it could open you up to attacks if you inadvertently download a malicious shell script file that is automatically opened by your web browser. Better to be explicit.

Upvotes: 2

Zifei Tong
Zifei Tong

Reputation: 1727

What you need is Platypus.

Platypus is a developer tool for the Mac OS X operating system. It can be used to create native, flawlessly integrated Mac OS X applications from interpreted scripts such as shell scripts or Perl and Python programs. This is done by wrapping the script in an application bundle directory structure along with an executable binary that runs the script.

Upvotes: 12

Related Questions