Run a command in a new tab with iTerm and AppleScript

A little script I use to save me some type everytime I want to start Jetty.

Put this in your .bashrc or .bash_profile

tab () {
  osascript 2>/dev/null <<EOF
    tell application "iTerm"
      tell the first terminal
        launch session "Default"
        tell the the current session
          write text "cd $PWD; $*"
        end tell
     end tell
   end tell
  EOF
}

Then run:

source ~/.bashrc

Use it with:

tab <my-command>

Example:

 tab cake run srcipts/run.clj
 tab compass watch myproject