How to run a shell script in OS X by double-clicking?

c2h2 picture c2h2 · Feb 26, 2011 · Viewed 288.7k times · Source

I have a shell script that has user execution permission on OS X, but when I double click on it, it opens in a text editor. How can I get it to run by double-clicking it?

Answer

Lus picture Lus · Feb 26, 2011
  • First in terminal make the script executable by typing the following command:

      chmod a+x yourscriptname
    
  • Then, in Finder, right-click your file and select "Open with" and then "Other...".

  • Here you select the application you want the file to execute into, in this case it would be Terminal. To be able to select terminal you need to switch from "Recommended Applications" to "All Applications". (The Terminal.app application can be found in the Utilities folder)

  • NOTE that unless you don't want to associate all files with this extension to be run in terminal you should not have "Always Open With" checked.

  • After clicking OK you should be able to execute you script by simply double-clicking it.