Clipboard Access From Shell (UTF-8)
Update 2011-01-27: Recent versions of Mac OS X make these replacements obsolete.
Two very nice shell commands that Apple has given us are the pbcopy
and pbpaste
commands. These allow stdin to go to the clipboard and the clipboard to be written to stdout.
Unfortunately the commands seem to use a combination of MacRoman and question marks for non-ASCII characters, which often makes them unusable for me, since I work with non-ASCII characters.
So today I decided to write a replacement for the two commands (yes, I did also file an enhancement report). You can download them here.
There’s just one source, it compiles to a command which works as pbcopy
, when called under that name, otherwise pbpaste
.
What I’ve done is place the command in ~/bin
and added a symbolic link from pbpaste
to pbcopy
, like this:
ln -s pbcopy ~/bin/pbpaste
And in addition ensured that my PATH contains ~/bin
before anything else, i.e. by placing the following in my ~/.bash_profile
(well, actually ~/.zshrc
):
export PATH="$HOME/bin:/opt/local/bin:$PATH:/Developer/Tools"
The source is included in the archive, and it’s very simple. No usage instructions etc., and it links with the Application Kit, since NSPasteboard is under that and not Foundation Kit.