Printing over SSH in MacOS X

Eric | May 2, 2009

This week I found out that I can easily do something in MacOS X of which I did not actually think that it was easily possible: print over ssh! This is very convenient for me because I don’t have a printer at home. So now when I find some interesting article on the web and want to print it it’s just a button click and on the next morning I will find the document lying in the printer at work! Here’s how it works…

Paste the following into a file, let’s say, named “Print to remote printer” and place it into ~/Library/PDF Services/.

#!/bin/bash
TITLE="${!#}"
cat "${TITLE}" | ssh name@your.server.com lpr -P printername

Obviously you need to exchange name etc for your proper parameters. I personally have two scripts, for two different printers. Make the script executable, e.g. using chmod 755. That’s it!

The next time you print a document, the script will simply show up as a button in the PDF menu. Could it be any easier?
screenshot
An added benefit is that your document will actually sent as PDF, not in a pixel format, so that should be relatively low on the network bandwidth, and certainly it’s not going to cost you more than any manual upload.

UPDATE:

If you have growl installed, then you may find the following script more useful instead. It automatically notifies you about whether or not the print job succeeded.

#!/bin/bash
TITLE="${!#}"
cat "${TITLE}" | \
ssh name@your.server.com lpr -P printername && \
/usr/local/bin/growlnotify -m "Successfully sent ${TITLE} to printer." || \
/usr/local/bin/growlnotify -m "FAILED to send ${TITLE} to printer!" -s

growlnotify is a command-line tool that comes with the growl download package but is not installed by the default installer. If it’s not on your system then you need to install it using the script in the download package for growl.

Categories
Misc
Tags
Mac
Comments rss
Comments rss
Trackback
Trackback