As of OSX 10.10 (Yosemite) and since at least OS X 10.8 (Mountain Lion), the behavior is as follows when you open (double-click) executable scripts from Finder:
.command
:Preferences... > Profiles
you can opt to automatically close the window when the script exits.cd -- "$(dirname "$BASH_SOURCE")"
right after the shebang linecd -- "$(dirname "$0")"
.chmod +x <script>
in Terminal; otherwise, you'll see the following symptoms:.command
: Finder displays a misleading error message that suggests the problem can be fixed via File > Get Info
, which is not true - use the chmod +x
method suggested above.#!/bin/bash
): behavior is as if the suffix were .sh
- see below..sh
, whether executable or not:TextEdit.app
or, if installed, with Xcode.app
..scpt
or .applescript
(even if they're themselves marked as executable, which is not normally the case):
[Apple]Script Editor
[1] Executable means: a script with the executable permission bit(s) set and the calling user - relative to the ownership to the file - therefore potentially being allowed to execute it.
If you use chmod a+x
to set all permission bits (which is typical), anyone can invoke it (assuming they're also allowed to read the file based on the read permission bit(s) and the file's ownership).
The easy way is to change the extension to .command
or no extension.
But that will open the Terminal, and you will have to close it. If you don't want to see any output, you can use Automator to create a Mac Application that you can double click, add to the dock, etc.
Automator
applicationRun
button in upper right corner to test it.File > Save
to create the Application.chmod 774 filename
Note: The file with name 'filename' that has the bash script has no extension
No need to use third-party apps such as Platypus.
Just create an Apple Script with Script Editor and use the command do shell script "shell commands"
for direct command calls or executable shell script files, keep the editable script file safe somewhere then export it to create an Application script. the app script is launch-able by double click or selection in bar folder.
Alternatively, you could create a regular Mac OS X application from your script using Platypus
Have you tried using the .command
filename extension?
You can also set defaults by file extension using RCDefaultApp:
http://www.rubicode.com/Software/RCDefaultApp/
potentially you could set .sh to open in iTerm/Terminal etc. it would need user execute permissions, eg
chmod u+x filename.sh
Source: Stackoverflow.com