Blog of roxlu, co-founder of Apollo Media. Contact info[shift+2]apollomedia.nl.

Auto start terminal app on mac

on run {input, parameters}
   tell application "Terminal"
        activate
                do script with command "cd /Users/roxlu/application && ./app someflag"
        end tell
end run

Or, use the recommended solution which is a bit more work: For interactive installations this is what I commonly use and which is great for e.g. service like apps. You need to create 2 files: one shell script which actually starts the application and a launchd script/xml file which is loaded when the mac starts.
There are several paths where you can store a launchctl script:

/Library/LaunchAgents:
Put your plist script in this folder if the job is only usefull when
users are logged in

/Library/LaunchDaemons:
Put your plist script in this folder if your job needs to run even when
no users are logged in

$HOME/Library/LaunchAgents:
This is the most safe option for installations! This will start when
the users logs in (also when automated login is enabled)

1) This script will make sure that the application will restart if it crashes, every 10 seconds:

$ emacs auto_start_streamer_app.sh                                                                                                                                                                      
#!/bin/bash                                                                                                                                                                                             
 
while true
do
  cd /Users/roxlu/homerecordings/streamer/bin && ./streamer -f online.cfg
sleep 10
done

2) Create this file in your home dir: /Users/roxlu/Library/LaunchAgents (mac 10.8.x)

$ emacs com.homerecording.streamer                                                                                                                                                                      
<?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>Label</key>                                                                                                                                                                                      
  <string>com.homerecording.streamer</string>                                                                                                                                                           
 
  <key>ProgramArguments</key>                                                                                                                                                                           
  <array>                                                                                                                                                                                               
    <string>/Users/roxlu/homerecordings/streamer/bin/auto_start_streamer_app.sh</string>                                                                                                                
  </array>                                                                                                                                                                                              
 
  <key>Nice</key>                                                                                                                                                                                       
  <integer>1</integer>                                                                                                                                                                                  
 
  <key>RunAtLoad</key>                                                                                                                                                                                  
  <true></true>                                                                                                                                                                                               
 
  <key>StandardErrorPath</key>                                                                                                                                                                          
  <string>/Users/roxlu/homerecordings/streamer/bin/launch.err</string>                                                                                                                                  
 
  <key>StandardOutPath</key>                                                                                                                                                                            
  <string>/Users/roxlu/homerecordings/streamer/bin/launch.log</string>                                                                                                                                  
</dict>                                                                                                                                                                                                 
</plist>

You can start a launch daemon using:

launchctl load /path/to/file.plist

And unload it with:

launchctl unload /path/to/file.plist

To check if your plist is loaded you can use something like:

launchctl list | grep "your label"