#!/usr/bin/env ruby # by NovaWave (http://www.novawave.net), but all credit goes to: # http://onrails.org/articles/2007/11/28/scripting-the-leopard-terminal # load AppScript bridge require 'rubygems' require 'appscript' include Appscript # access the terminal and create a new tab term = app('Terminal') app('System Events').application_processes["Terminal.app"].keystroke("t", :using => :command_down) # execute the command in that tab window = term.windows.first term.do_script("cd #{ARGV[0] || `pwd`}; clear", :in => window.tabs.last.get)