Send command to terminal from emacs

I've found a solution that seems to be working nicely.

Using tmux, I can send a command to a running session like this:

(defun es-send-via-tmux (command)
  (message (concat "running: " command))
  (call-process "/usr/local/bin/tmux" nil nil nil "send-keys" "-t 1" command "C-m")
 )

E.x.:

(es-send-via-tmux "echo hello") 

If you are really just concerned about output quality, why not call uxterm with the -hold option as so?

(defun external-xterm-shell-command (COMMAND)
  "Run a terminal command in an external xterm window."
  (interactive "sShell Command: ")
  (shell-command (concat "uxterm -hold -e " COMMAND)))

Been some time since I used OS X. IIRC, you can use the osascript utility to run AppleScript which could be used to send a command to Terminal.app. Something like:

tell application "Terminal"
  do script "ls"
end tell

Tags:

Macos

Emacs