Run a shell script on OS X without having a terminal window appear?

Open Automator, choose Application, add a Run Shell Script action and put in your Shell command between quotes (if you have a file, you can just drag and drop it).

Other than playing it, now you can save it (as an app anywhere) and even set the icon.


Here's a quick and dirty example with almost no effort (for an app named "myapp"):

  1. Make an partial applications hierarchy:

        mkdir -p ./myapp.app/Contents/MacOS
    
  2. Make sure the first line of your script has the full path to the needed program, e.g.,

    #!/bin/bash
    
  3. Name your shell script "myapp" (no quotes, no extension), give it execute permissions, and then put it in the MacOS sub-directory. To give it execute permissions:

    chmod ugo+x myapp
    
  4. Go to the Contents sub-directory and create a PkgInfo file containing the string: APPL???? [no line terminator at end of string!] Use the cat(1) utility to create the file:

    cat > PkgInfo
    APPL????
    

    After you have typed the string (do not hit return!), enter two control-D's, which will close
    the file with no line terminator and return you to the shell prompt.)

  5. Double-click your new "app" from the finder. It will run with no window.


You might want to check out Platypus, which creates Mac OS X applications from shell scripts and other interpreted scripts.


Here's a small workaround, in case you fancy application launchers like Alfred. I use it every day, and I've bought the Powerpack, which allows you to run silent shell scripts.

enter image description here

These will not open a terminal when running and can be bound to any keyword sequence. They can even include parameters, and have additional options:

enter image description here

I use this for some small snippets, and it's very flexible.


If you add key LSUIElement and set it to 1 in Info.plist of your app, it will not create an icon in Dock.

Here is Info.plist of my small shell script app:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleExecutable</key>
    <string>launch</string>
    <key>CFBundleIconFile</key>
    <string>launch</string>
    <key>LSUIElement</key>
    <string>1</string>
</dict>
</plist>