Command line printing on Mac OS X

by ,

I have this thing for printing in 2 columns.
I bothers me that there are no web browsers that supply an option to print web pages in 2 columns.
Most web pages are in a silly fixed-width format that wastes tons of paper when printed.
Ideally, good web sites would have print-specific CSS files that open up the columns when printing, and indeed a few do.
However, the vast majority do NOT.

I was going to print some code today and remembered that I had scripts from the Alias days that printed things nicely in 2 columns.
After some scrounging, I found that the scripts were based on “enscript”, then an expensive, proprietary offering (apparently).
Now it’s open source, or maybe someone wrote an open-source replacement and named it the exact same name.
Well, whatever the case, it’s a part of Mac OS X (10.3 at least) in /usr/bin/enscript.

So here is the magic command line I used to print my file (which btw, was part of Apple’s MoreIsBetter line of sample code):

enscript -G2E -fCourier5 -T 4 MoreSCFHelpers.c -p ~/Desktop/ && open ~/Desktop/

Now, what this does is to “print” the code to PostScript, save it in a file on my desktop (named “”), and then open that file, which causes Preview to convert it to PDF and then display it.
Sort of a “print preview”, if you will.

I’m sorry, but I found this to be way to useful not to share.
Also, since Mac OS X now uses the Unix “CUPS” printing architecture, all the command-line print queues are the same as those available in your “Print” dialogs.
Just open iTerm (or Terminal if you only have that) and type the command “lpstat -a“.
On my G5 at home I get:

% lpstat -a
Downstairs_LaserJet accepting requests since Jan 01 00:00
Epson1 accepting requests since Jan 01 00:00

Btw, while we’re talking about the command line and printing, did you know that you can get really nicely formatted versions of most Unix “man pages”?
Just use the “-t” option and it spits out some nice PostScript.
You can either save it to the desktop like the above, or just pipe it straight to “lpr”:

man -t genstrings | lp -d Downstairs_LaserJet

If you want to set the default command line printer destination (which apparently is separate from the UI one), use the “lpadmin” command:

lpadmin -d Downstairs_LaserJet

Fun, eh?

development, software.

About rae

I'm a long-time Mac and iOS developer. I'm also a big fan of Ruby on Rails and relational databases. I tend to work remotely, in my basement with occasional trips to the office. I'm also a big videophile, both TV and film, and can't wait for a good, inexpensive home 4k solution.

1 Comment “Command line printing on Mac OS X

  1. David "You Lost Me At 11:02 am" Barker


    You know like no offense.


Leave a Reply

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