launchd in 10.5 introduces a couple of new flags to the launchd config plists, specifically KeepAlive (bool or dict) and SuccessfulExit (bool, as child of KeepAlive dict). Using these flags, you can tell launchd to launch an application and automatically restart it if it crashes, but NOT if it exits cleanly. This previous hint showed a somewhat different approach to accomplish the same thing.
Using my company's flight management software as an example, you would end up with the following LaunchAgent .plist file, which I put in my home Library/LaunchAgents folder:
<?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>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
<string>com.frontierflying.flightmaster</string>
<key>ProgramArguments</key>
<array>
<string>/Users/Shared/FlightMasterStandalone/FlightMaster2004.app/Contents/MacOS/EXE</string>
</array>
</dict>
</plist>Of course, this loads immediately at login. If this is the desired behavior, then you are done. If you don't want this, then put the .plist file in your documents directory or something, and use something like the following two-line script to load it as desired:
launchctl unload /path/to/launchagent.plist
launchctl load /path/to/launchagent.plst
The unload command is needed only if you want to launch the application multiple times in a session. From what I can tell, once loaded, the LaunchAgent remains loaded, and simply stops monitoring the app after it quits cleanly -- but doesn't unload.
Mac OS X Hints
http://hints.macworld.com/article.php?story=20071220095645567