How do I copy to the OSX clipboard from a remote shell using iTerm2?

333 views
Skip to first unread message

Joe Casadonte

unread,
Oct 17, 2016, 9:06:46 PM10/17/16
to iterm2-discuss
Using iTerm2, I start an interactive SSH session to a remote Linux machine (where pbcopy is not available). On the remote Linux machine I would like to capture the output of some arbitrary command (e.g. ls *.foo), and have it magically appear in my OSX clipboard, so that when I hit +v it appears in whatever OSX application I've just pasted into. Is this possible? I've tried the escape codes mentioned on the iTerm2 doc page and can't make them work.


Thanks!

George Nachman

unread,
Oct 20, 2016, 2:32:32 PM10/20/16
to iterm2-...@googlegroups.com
This command copies to the clipboard and also echos to the screen:

printf '\033]1337;CopyToClipboard=\007'
ls *.foo
printf '\033]1337;EndCopy\007'

This command copies to the clipboard without echoing:

printf '\033]52;;'
ls *.foo | base64
printf '\007'

You must have "Prefs > General > Applications in terminal may access clipboard" enabled, and "Prefs > Advanced > Disable potentially insecure escape sequences" turned off.



On Mon, Oct 17, 2016 at 6:06 PM, Joe Casadonte <northboun...@gmail.com> wrote:
Using iTerm2, I start an interactive SSH session to a remote Linux machine (where pbcopy is not available). On the remote Linux machine I would like to capture the output of some arbitrary command (e.g. ls *.foo), and have it magically appear in my OSX clipboard, so that when I hit +v it appears in whatever OSX application I've just pasted into. Is this possible? I've tried the escape codes mentioned on the iTerm2 doc page and can't make them work.


Thanks!

--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joe Casadonte

unread,
Oct 21, 2016, 2:41:47 PM10/21/16
to iterm2-discuss
I've pulled together a nice solution using launchd and netcat. If anyon'e interested, details are here:

http://apple.stackexchange.com/a/258168/27844
Reply all
Reply to author
Forward
0 new messages