Wednesday, May 09, 2007

Nice to know - MacOSX

The print subsytem on MacOSX is simply CUPS!

For a long time I have had one simply, but nagging issue with my Mac computers - printing from the command line. But it hasn't bothered my enough to actually solve the problem. Today, however, one of our Mac converts (or at least wannabies) entered my office with the intention of insulting the Mac. He started like "I want to run acroread from the command line," remember, his background is Linux. No problem I said, you just use open -a AdobeReader.app. No, no, he goes, I just want to process some PDFs into postscript. Why do you want to do that - the Mac handle pdf quite well? And the reason was that, because we didn't knew how to print from the command line, he send jobs to printers through a Linux server. And the Linux server needs postscript.

Aha, great opportunity to solve the cli printing issue. Now, I know of course that lpr is available. Problem is, though, that if I use that from the commandline, I don't know what the names of the printers are supposed to be - the argument to the -P option. And by default, the printing system thinks everything should go to the printer in Letter format, which does not work very well with our European printers. They want A4. And I know how to change paper size to A4 in the GUI, but this will not be the default anyway. At least not when you print with lpr from the command line, should you be lucky enough to hit the right printer.

I have heard some whispering about the print subsystem just beeing cups in the past. So I just gave it a shoot, typing in http://localhost:631 in my browser. And I just goes wow, wow, wow. Because what I see is just the regular, no-frills, cups admin system. With all the printers listed. And selecting "configure printer", I have the option of changing default paper size. I can even see the names of the printer queues. So, selecting one I like to use, changing the paper size, and then try out lpr -Pprinter file.pdf, and run off to the printer. And what do I see? The file.pdf appears as it should, on A4 paper and everything is just fine.

After clicking around in the cups admin system for a few more minutes, I had the printer I like to use most set as default and the paper size set to A4 for the most important once. I also figured out that I can do a grep on the file /etc/cups/printers.conf to get the list of available printers. Looking at the names, it is quite easy to figure out the mapping from printer to queue name. The grep commando I use is this one:

sudo grep "<Printer" /etc/cups/printers.conf | awk "{print \$2}" | sed "s/>$//"


Hope this of some interest to someone out there in the void!

Take care,

No comments: