Jens Nöckel's Homepage

Computer notes home

Droplet script launcher

Here is a simple way of making shell scripts into clickable applications under Mac OS X. This is one of the standard problems one encounters when trying to integrate command-line or X11 applications into the Mac OS X user interface, as I discuss more generally on a separate page.

On this page, I discuss how to solve the problem using AppleScript to processes files dropped onto the application by passing them to the argument list of the shell script. By separating the launcher's shell script portion from the Applescript (as is done below), you have some added flexibility if you want to modify the shell script without changing the rest of the Application.

The reason why this approach may be preferable to an Automator workflow is that AppleScript works on a larger range of Mac OS X version, while Automator won't work on older versions such as Tiger. I also like to keep this code around as a template for more complex AppleScript applications.

One thing the approach below doesn't do is create an application that can serve as the default application for opening certain file types. If you need that capability, use Automator instead.

Now for the details of the AppleScript approach. In AppleScript Editor, enter the following code (here for xemacs as an example):



To wrap another command, simply replace xemacs by whatever you want. The AppleScript responds to two events:

Save as Application and add the following shell script to the Scripts Folder in the bundle, under the name launcher.sh:

#!/bin/sh
exec "$@" < /dev/null >/dev/null 2>&1 &
echo $!

This shell script launches a command without waiting for input or output other than the PID.

Make the script launcher.sh executable with chmod 700 launcher.sh

Then save the bundle from AppleScript Editor. The result is a launcher application that can be dragged into the /Applications directory.


noeckel@uoregon.edu
Last modified: Sun Jul 31 23:08:41 PDT 2011