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?
Macos – How to run a shell script in OS X by double-clicking
desktopmacosscriptingshell
Related Topic
- Linux – How to prompt for Yes/No/Cancel input in a Linux shell script
- Bash – How to tell if a regular file does not exist in Bash
- How to mkdir only if a directory does not already exist
- Bash – In the shell, what does ” 2>&1 ” mean
- Bash – How to split a string on a delimiter in Bash
- Windows – How to run a PowerShell script
- Bash – How to set a variable to the output of a command in Bash
Best Answer
First in terminal make the script executable by typing the following command:
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.