ターミナルを現在のフォルダで開く
これまでOpenTerminalを使っていたのですが、どうせならこれもということでAppleScriptで書いてみました。
スクリプトエディタでアプリケーションとして保存して、Finderのツールバーに配置すればOKです。
tell application "Finder" if Finder window 1 exists then try set select_item to selection as alias set folder_selected to (select_item as string) ends with ":" on error set folder_selected to false end try if folder_selected then -- when Folder selected set target_path to POSIX path of select_item else -- when Folder opened set target_folder to target of Finder window 1 set target_path to POSIX path of (target_folder as alias) end if tell application "Terminal" do script "cd " & (quoted form of (target_path as text)) activate end tell else -- when no Finder window tell application "Terminal" do script "" activate end tell end if end tell
キー入力を送るようなことが必要かと思ってましたが、do scriptは、ターミナルを新たに開いて指定したコマンドを実行させた上で、スクリプトが終了してもそのウィンドウは残ってくれるという素晴らしい仕様です。
それにしてもAppleScriptは、英語とPascalとAdaの折衷のような構文で、各アプリケーション専用の構文を追加しているあたりBASICしてて、非常に気分が良いですね……。下手すると私スクリプト言語は汎用である必要は無いとか言い出しそうです。まだ1日しか使ってないですけど。