[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: send selection or current line to Terminal/iTerm

From: klebsiella
Subject: Re: send selection or current line to Terminal/iTerm
Date: Fri, 13 Jun 2014 06:39:36 -0700 (PDT)

So guys,

First thank you all for your time.

Here is the code in my .emacs (see below) that is supposed to do the job
(Thanks go to @JordonBiondo - Stackoverflow and also to you John Mastro)

I am now working on emacs (not Aquamacs) and the code is still not working.
Again, as I do not know Lisp, it was hard for me to debug !!! 

The error message given is I guess thrown by osascript, but may be linked to
a syntax problem in lisp:

100:100: syntax error: Expected string but found end of script. (-2741)
Process send-text-iterm2-proc exited abnormally with code 1

Osascript itself is working. For instance the following line runs correctly
on the terminal:

$ osascript -e 'tell application "iTerm" ' -e 'set mysession to current
session of current terminal' -e 'tell mysession to write text "ls"' -e 'end

It would be great to make it run (For everybody I believe)

.emacs related chunk
(defun sendtext:escape-text(s):
    (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*"
                   "-e" "tell app \"iTerm\""
                   "-e" "set mysession to current session of current
                   "-e" "tell mysession to write text \""
                   (sendtext:escape-text text)
                   "-e" "end tell")))
John Mastro wrote
> Hi klebsiella,
> John Mastro <

> john.b.mastro@

> > wrote:
>> This is totally untested (sorry, still not around a Mac), but I think
>> something along these lines should work. Assuming that SublimeText
>> extension works anyway.
> By the way, if the code I posted does do approximately want you want,
> I'd be happy to improve it a bit for you (e.g. handling escaping, as the
> SublimeText version seems to).
> If you try it, let me know if/how it works for you.
> - John

View this message in context:
Sent from the Emacs - Help mailing list archive at

reply via email to

[Prev in Thread] Current Thread [Next in Thread]