Setting up lpd printing on OS X

Dec 21, '01 10:33:21AM

Contributed by: eagle

lpd is the standard Unix printing system, so others who come from the Unix community (as I did; a longtime Linux and NeXT user) might be interested in sharing their printers to their other Unix machines.

See, not having lpd as the printing system in OS X was a big bummer to me, because it meant that I could no longer print with my NeXT and other Unix computers, because my printer is now hooked to my G4 Cube (permanently assigned to OS X 10.1). With this little hacked up lpd, I can now do that again. :)

Read the rest of the article for the how-to.

[Editor's note: I have not done this on my machine as of yet, but 'eagle' vouches that it works but only on PostScript printers! Any errors in the following article are a result of my formatting work; please let me know if you see any troublesome lines!]

Here's how to get lpd working:

1] Create the printcap entry. Here's the entry I used:

lp: \
:sh=true:of=/Users/foo/Applications/lpd-hack: \
:lf=/var/log/lpd-errs:sd=/var/spool/output/lpd:lp=/dev/null:
The options are:After you have edited /etc/printcap, simply run:
niload printcap / < /etc/printcap
2] Save the following as the script pointed to by the "of=" parameter above
#!/usr/bin/env perl
$temp_file = "/tmp/printing.$$";

# LPD passes via STDIN the file to be printed
# (we don't have any knowledge of the original filename...too bad)
# save this as a file to be processed
@lines = <STDIN>;
open(TMPFILE,">/tmp/printing.$$");
print TMPFILE @lines;
close(TMPFILE);

`/usr/sbin/Print /tmp/printing.$$`;
`/bin/rm -f /tmp/printing.$$`;
Don't forget to make the script executable.

3] Start lpd. lpd resides at /usr/libexec/lpd. Simply run "/usr/libexec/lpd" as root from the command line.

4] Restart the queue. Run "lpc" and issue the command "restart all" then exit lpc.

5] Now print. Make sure the $PRINTER environment variable matches the name of the printer in the printcap entry. The default printer is "lp" so if you use the above, you need not set $PRINTER. Print using the command lpr, as in:
lpr file.txt
lpr file.ps
lpr file.pdf
With this setup, you can print text, PostScript and (!) PDF files. Additionally, you can share a networked printer. Simply add the remote machine's DNS name (haven't tried IP address yet but I would bet that it works) to /etc/hosts.lpd or /etc/hosts.equiv on the OS X box, you can configure /etc/printcap on the remote machine and use lpr/lpd on the remote machine to spool to a printer on the OS X box.

Enjoy! Mail me with any questions.

Comments (9)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20011221103321129