EmacsからiTermに対してコマンドが送りたい時がある。例えば
など。
そういう時には以下の様なユーティリティを定義しておくと便利。AppleScriptを利用して、iTermにコマンドを送る。
(defun execute-on-iterm (command) (interactive "MCommand: ") (do-applescript (format "tell application \"iTerm\" activate tell current session of current terminal write text \"%s\" end tell end tell" command)))
これを利用して「現在Emacsで開いているファイルのディレクトリにiTermで移動したい」を実現するには以下のように書くだけで良い。
(defun cd-on-iterm () (interactive) (execute-on-iterm (format "cd %s" default-directory)))