EclipseからiTermで開く。当然Finderも大丈夫だよ。

この手のツールは、ずっとOpenExternalを使っていたのですが、普段コンソールはiTermをメインで使ってるので、ターミナルではなくiTermで開けるものはないかずっと探してました。

そこで見つけたのがこれ。

Path Tools - http://code.google.com/p/pathtools/

インストールはアップデートサイトから
http://pathtools.googlecode.com/svn/trunk/PathToolsUpdateSite/site.xml

Path Toolsもデフォルトではターミナルです。Open Externalと違うのはAppleScriptファイルをプラグインから叩いているところ。OpenExternalはこのAppleScriptがコードの中にべた書きされているようです。ようはこのファイルを書き換えれてやればiTermで開ける!

ってことでインストールが完了したらEclipseの環境設定からPath Toolsの画面を開きます。
f:id:yamkazu:20100303211620j:image
その中からShell at Folderに設定されているcdterminal.scptのパスを調べます。

あとはこのファイルをAppleScriptエディタで開いてiTerm用に書き換えてやります。別にファイルを作ってEclipseの参照先の設定を変えてもOKです。

AppleScriptはここを参考にやりました。
http://michaelangela.wordpress.com/2009/12/14/pathtools-and-iterm-instead-of-terminal-3/
そのままだとiTermのWindowが無いときにエラーになってしまうようだったので一行だけ追加しました。これでいいのかよく解らんが動いてます。
内容はこんなかんじ。

on run argv
	set cdTo to item 1 of argv
	tell application "iTerm"
		activate
		make new terminal
		tell the first terminal
			try
				launch session "Default Session"
			on error
				display dialog "There was an error creating a new tab in iTerm." buttons {"OK"}
			end try
			tell the last session
				try
					write text "cd " & cdTo
				on error
					display dialog "There was an error cding to the requested path." buttons {"OK"}
				end try
			end tell
		end tell
	end tell
	return
end run

これでEclipseからiTerm、Finderで開ける環境ができました!
iTerm大好きなひとはお試しあれ。