Converting a Shell Script Into a *.app File
Just to mention it, if you Get Info on a script, you can set it to be opened with the Terminal. This will run the script when you double-click it.
Otherwise, packaging a script in a .app bundle is trivial. Mac OS X will happily run any script identified as the application's executable.
At a minimum, you need to following structure in place:
- (name).app
- Contents
- MacOS
- (name)
- MacOS
- Contents
Where the file called (name) is your script (which must be executable, and must have a shebang line). (name) must be identical in the .app directory and the script file: for instance, if your app directory is called "My Shell Script.app", then the file inside the MacOS directory must be called "My Shell Script", with no extension.
If this is inconvenient, it's possible to use an Info.plist file to specify an alternate executable name. The Info.plist goes in the Contents directory:
- Wrapper.app
- Contents
- Info.plist
- MacOS
- MyScript
- Contents
This structure (a MyScript executable in a wrapper called Wrapper.app) works if you specify MyScript as the CFBundleExecutable
in the property list:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>MyScript</string>
</dict>
</plist>
Using an Info.plist file is probably preferable, as that will allow you to rename your wrapper without breaking it.
Here's one example script that uses /bin/sh
as the interpreter, but you really could have anything (#!/usr/bin/swift
, #!/usr/bin/python
, etc).
#!/bin/sh
open -a Calculator
The script will run as you double-click the app bundle.
You can bundle anything else that you need with your script within the Contents
directory. If you feel fancy, you can reproduce the standard executable bundle layout with a Resources
directory and things like that.