Skip to content

Instantly share code, notes, and snippets.

@jordonbiondo
Last active February 6, 2023 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jordonbiondo/9981411 to your computer and use it in GitHub Desktop.
Save jordonbiondo/9981411 to your computer and use it in GitHub Desktop.
(defun sendtext:escape-text(s):
(with-temp-buffer
(insert s)
(replace-string "\\" "\\\\" nil (point-min) (point-max))
(replace-string "\"" "\\\"" nil (point-min) (point-max))
(buffer-substring-no-properties (point-min) (point-max))))
(defun sendtext:send-iterm2(beg end)
(interactive "r")
(let ((text (buffer-substring-no-properties beg end)))
(start-process "send-text-iterm2-proc" "*sendtext:output*"
"osascript"
"-e" "tell app \"iTerm\""
"-e" "set mysession to current session of current terminal"
"-e" "tell mysession to write text \""
(sendtext:escape-text text)
"\""
"-e" "end tell")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment