Saturday, March 14, 2009

Printing from the command line in Mac OSX

I had to print close to 50 individual PDF files and one way to do that was to open each one of them and then print them. But there is a fundamental issue with that. I am lazy. Opening 50 files and then printing them was not something I wanted to do on a Saturday morning.

So, I fired up the browser and started searching for ways to print from the command line and got lucky with the first hit. 'lp' is a command line tool that submits files for printing or alters a pending job and it is very easy to use. To print a bunch of pdf files in a folder, type the following commands in the terminal:
# Printing to default printer.

lp *.pdf

# Printing a document to the default printer in landscape mode

lp -o landscape foo.pdf

# Printing the first and the second pages of the document

lp -P 1,2 foo.pdf

# Printing pages between 4 and 20 in landscape mode

lp -P 4-20 -o landscape foo.pdf

# Printing to a non-default printer called "bar"

lp -d "bar" foo.pdf
More information is available in the man document for 'lp'.

P.S.: I did not use 'really' in this blog post. Oops!! I think I just did it again.

No comments: