I ran into this same problem, and found the following solution. I modified (very slightly) this gist, and added it as a package to Aquamacs.
Here are the basic steps:
Copy the gist above into a new file, and then change the function iterm-send-string to the following:
(defun iterm-send-string (str)
"Send STR to a running iTerm instance."
(let* ((str (iterm-maybe-remove-empty-lines str))
(str (iterm-handle-newline str))
(str (iterm-escape-string str)))
(shell-command (concat "osascript "
"-e 'tell app \"iTerm2\"' "
"-e 'tell current window' "
"-e 'tell current session' "
"-e 'write text \"" str "\"' "
"-e 'end tell' "
"-e 'end tell' "
"-e 'end tell' "))))
To make this a package you can add the following to the top of the file
;;; iterm.el --- sends selections to iTerm.app -*- lexical-binding: t; -*-
;; modified from: https://gist.github.com/johnmastro/88cc318f4ce33b626c9d
;; Author: David Little <[email protected]>
;; Keywords: lisp
;; Version: 0.0.1
;;; Commentary:
;; Works on Mac OS X: sends a selction to iTerm
;; To match SublimeText's key binding:
;; (global-set-key (kbd "<C-return>") 'iterm-send-text)
;;; Code:
Then you just need to call M-x package-install-file. Once you bind the iterm-send-text function to a shortcut (e.g. C-return in the comments above) you should be in business!
start-processin Emacs, I may try it myself if I get time. In fact, I got started on it, but I'm not on a osx machine so I can't test it: gist.github.com/9981411M-x sendtext:send-iterm2. This gave the following error "The mark is not set now, so there is no region". As I do not know lisp and python, it was hard to me to debug. Did it work in your hand ?isend-mode. Mainly, I followed the instructions on (github.com/ffevotte/isend-mode.el) and bound the send key with:(eval-after-load "isend-mode" '(define-key isend-mode-map (kbd "C-c RET") 'isend-send)). Hope this will help others... Thanks JordonBiondo