A couple of suggestions. First there's the logging function under
"Session -> Log". This isn't quite what you asked for but it
might be what you actually want. It captures all output to a file.
(It would be kind of cool if you could log to the clipboard,
though!)
Second, it's possible to set up something with triggers and
coprocesses. If you google for "iterm coprocess zmodem" you can find
some examples using zmodem to transfer files from a remote system.
Since it's using the regular terminal stdio channel it doesn't
matter how many hops or VPN logins are between you and your remote
host. You do have to have the zmodem commands installed though.
(Typically 'sz' on the sending side, 'rz' on the receiving side.)
I don't have the luxury of installing software on my remote hosts,
and zmodem isn't available. Instead I wrote my own cheap
alternative. I set up the following bash function on my remote host:
sendfile ()
{
echo '-*-{{SENDFILE}}-*-';
echo "{\"version\": 1.0, \"host\": \"`hostname`\"}";
env COPYFILE_DISABLE=true tar czf - "$@" 2> /dev/null | base64;
echo '-*-{{DONE}}-*-'
}
What this does is sends the string "-*-{{SENDFILE}}-*-", which is a
unique string I can use to trigger a coprocess. Then it sends a
line of JSON with the protocol version and the name of the sending
host. After that it runs 'tar' to bundle up all the files I
specified on the command line, filters the result through base64,
and prints it to the terminal.
On my Mac I set up a trigger in iTerm to run a coprocess when it
sees that "-*-{{SENDFILE}}-*-" string. The coprocess is a python
script which is expecting a line of JSON followed by a
base64-encoded tar file. Once the tar file is received the coprocess
decodes and unpacks it to my ~/Downloads directory. It could easily
be modified to write files to the clipboard if desired. I'm not
completely happy with it (it bogs down on large files, I'm not sure
why) but I'll post it to GitHub when I get a chance. (The repo is
at
https://github.com/SteveKing/sendfile but it's currently empty.)