Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kyab/771834 to your computer and use it in GitHub Desktop.
Save kyab/771834 to your computer and use it in GitHub Desktop.
(XCode4非対応)XCodeで現在開いているソースファイルのフォルダからターミナルを開始します。「ユーザスクリプトの編集」でディレクトリを「選択部分」にしておいてください。
#!/usr/bin/ruby
#カレントディレクトリを取得
dir = `pwd` #エディタにフォーカスがないと、上手くそのファイルのディレクトリに移動できない・・。
puts dir
#ターミナル.appにさせる処理(AppleScript)を文字列に詰める
terminal = "\\\"Terminal\\\"" #\"Terminal\"
cmd1 = "\\\"cd /\\\""
cmd2 = "\\\"echo foo\\\""
cmd3 = "\\\"cd #{dir}\\\""
script = <<SEND
tell application #{terminal}
activate
-- do script with command #{cmd1}
-- do script with command #{cmd2}
do script with command #{cmd3}
end tell
SEND
p script
`osascript -e "#{script}"`
#ターミナルの扱いについては、OpenTerminalHereのスクリプトを参照した。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment