Ever wanted to send text snippets from one machine to another via the Terminal? Save this XML code to a file named pbcopy.plist in your user's Library -> LaunchAgents folder (note that you'll probably have to create the LaunchAgents folder).
Next, execute this command in Terminal (or just logout and login):
$ launchctl load ~/Library/LaunchAgents/pbcopy.plist
Now you'll be able send any text over the network right to the clipboard on this machine via nc (netcat) or bash, like this:
$ echo test | nc -w1 1.2.3.4 2224 [or]
$ echo test >/dev/tcp/1.2.3.4/2224
Note that the second example is a bash feature and may be disabled on some systems. In both examples, replace 1.2.3.4 with the IP address of the receiving Mac (the one running the XML code), and make sure your firewall allows access to port 2224.
<key>SockNodeName</key>
<string>127.0.0.1</string>
Once that's done, you may access the service from a remote machine on 127.0.0.1:2224 if you ssh there with this option in the .ssh/config file:
RemoteForward 2224 127.0.0.1:2224
This one is a default for all my ssh connections, because very often I need to transfer a lot of text output to my local machine from many kinds of unixes. Unfortunately, Terminal's cut-n-paste can't handle this without breaking lines or truncating the text to the size of the scroll buffer.
Mac OS X Hints
http://hints.macworld.com/article.php?story=20050914005310534