41

You can create a shell script or a Python or Ruby script and run it on the Mac by using "Terminal" ... if you have Finder open, and you click on the icon for the file containing the source code of a saved shell script, is there a way to have that script run, instead of opening in my text editor ?

Paul R
  • 208,748
  • 37
  • 389
  • 560
dreftymac
  • 31,404
  • 26
  • 119
  • 182

3 Answers3

95

Yes - just put a .command suffix on the script.

Note: make sure the script is executable, e.g.

$ chmod +x myscript.command
Paul R
  • 208,748
  • 37
  • 389
  • 560
7

Just another quick alternative is the tool platypus (http://sveinbjorn.org/platypus/). Free and good, but you can donate, if you want.

Platypus is a developer tool for the Mac OS X operating system. It creates native Mac OS X applications from interpreted scripts such as shell scripts or Perl, Ruby and Python programs. This is done by wrapping the script in an application bundle along with a native executable binary that runs the script.

alexrjs
  • 546
  • 8
  • 15
2

just associate .sh files with Terminal.app

namon
  • 55
  • 1
  • 4
    This makes the file non-portable (.sh files are opened by XCode, for instance). – Eric O. Lebigot Nov 30 '11 at 09:44
  • 1
    Actually, it's not a terrible solution if you do a Finder -> Get Info -> Open with: -> Terminal (and NOT click the Change All... button). You'd be changing the default only for this file itself. – Michael Blankenship Jan 31 '16 at 17:17