pbcopy : A shell user’s friend.

I have been using Mac OS X in one flavor or another for over 4 years now. I make extensive use of the terminal, scripts and general UNIX automation in my workflow. For example I use a large collection of scripts to massage data and format it. Some of these scripts use an SQL query to rip data from bugzilla to build a report. The most common thing I do with these reports is convert them to mediawiki table markup and toss them on a wiki page as a status snapshot or other tabular form presentation.

This has proven awkward as I run my script, put it in a temporary file, open the file in TextEdit and select-all and paste into the web-browser window that is editing the wiki page. I remember from my X11 days there was a utility to load stdin and stdout to the ‘cut buffer’. Can we manipulate OS X’s paste board from the CLI?
Yup. man pbcopy
RTFM on this fine fellow: pbcopy. In fact, pbcopy also has pbpaste as a friend.

These commands let your source (from the paste board) and sink (to the pasteboard) your standard input.

So now, my workflow is more like:

$ script | pbcopy

And then I can immediately paste into the web browser form.

A very handy improvement on efficiencies.

3 thoughts on “pbcopy : A shell user’s friend.

  1. I guess I see the point of pbcopy, but I don’t get pbpaste. Why not just use cmd-V?

    To partly answer my own question, my one irritation with cmd-V is that the buffer often contains a newline, in which case pasting onto the command line with cmd-V (after an “echo” if necessary) executes the command. However, I may want to pipe the buffer into something else or I may need to close a quote. I guess pbpaste gets around that problem. Anything else?

  2. pbpaste would be good in a script – you could have the script work on the current paste buffer. That would be the one application that makes the most sense to me.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>