Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Setting up lpd printing on OS X UNIX
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: \
The options are:
  • sh=true -- suppresses the header page (sh=true is required to print PostScript and PDF files)
  • of=.../lpd-hack -- this is the Output Filter that lpr will use. This is what actually prints the file. The of parameter must point to the actual executable script.
  • lf=/var/log/lpd-errs -- this was in there by default and I didn't remove it
  • sd=/var/spool/output/lpd -- the spool directory; needs to be a valid directory
  • lp=/dev/null -- the device where the printer exists; I use /dev/null because I have no printer device!
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>;
print TMPFILE @lines;

`/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.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.
  • Currently 2.50 / 5
  You rated: 4 / 5 (4 votes cast)

Setting up lpd printing on OS X | 9 comments | Create New Account
Click here to return to the 'Setting up lpd printing on OS X' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
doesn't work for me
Authored by: wealthychef on Jan 15, '02 06:41:20PM

I followed these instructions verbatim. I understand Unix, but not lpd very well. It just doesn't work for me. When I try to print, it complains:

[richcookmac:~] rcook% lpr -Pcascptr3
jobs queued, but cannot start daemon.
[richcookmac:~] rcook% lpq
Warning: no daemon present
Rank Owner Job Files Total Size
1st rcook 4 117 bytes
[richcookmac:~] rcook% ps -auwxx | grep lpd
root 296 0.0 0.1 5108 384 ?? Ss 0:15.10 slpd -f /etc/slpsa.conf
root 12408 0.0 0.0 1340 112 ?? Ss 0:00.01 /usr/libexec/lpd


[ Reply to This | # ]
doesn't work for me
Authored by: wealthychef on Jan 15, '02 07:39:57PM

I guess I should show the relevant part of my /etc/printcap:


There is no /var/log/lpd-errs file being created.

[ Reply to This | # ]
doesn't work for me
Authored by: eagle on Feb 04, '02 03:03:58PM

The lpd errors file won't be automatically created. Touch it as root, then retry. Feel free to mail me and we can try to work through your lpd problems.

[ Reply to This | # ]
HP G85
Authored by: WillyT on Jan 18, '02 08:42:24PM

This works with my HP G85 printer but only for pdf files. This is probably because it is NOT a postscript printer. The Print command calls enscript for text files.

What I don't understand is why Print doesn't work from the terminal but does from the Perl script?

Do You know of something that I could substitute for enscript that would convert ps2pdf?

[ Reply to This | # ]
HP G85
Authored by: eagle on Feb 04, '02 03:07:00PM

Don't know what you mean about Print working from Perl but not from the shell. Would you mail me an example?

Also, it might have worked for PS files for me because my testbed contained an HP LaserJet. :)

[ Reply to This | # ]
Works only with PDF
Authored by: ujwal on Feb 10, '02 04:14:50AM

Thanks for your tips. However, /usr/sbin/Print works only with PDF on my HP PSC 750 (non-PS) printer. I had to modify your script to convert everything to PDF:

#!/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
# This filter eventually calls /usr/sbin/Print. Print likes to print PDF
# files and does not seem to like anything else, so convert to PDF

@lines = <STDIN>;
print TMPFILE @lines;
# Enscript does not pass through PDF, so do it here
if ( $lines[0] =~ /%PDF/ ) {
`cp /tmp/printing.$$ /tmp/printing.$$.pdf`;
else {
`enscript --pass-through --no-header -o /tmp/printing.$$.ps /tmp/printing.$$`;
`ps2pdf /tmp/printing.$$.ps /tmp/printing.$$.pdf`;
# Now print the PDF file
`/usr/sbin/Print /tmp/printing.$$.pdf`;
`/bin/rm -f /tmp/printing.$$ /tmp/printing.$$.ps /tmp/printing.$$.pdf`;

[ Reply to This | # ]
Works only with PDF
Authored by: goedel on Apr 18, '02 06:57:40AM

That's funny!... I tried the script (btw, many thanks to eagle!), but for my nearest networked printers (HP LaserJet 2100TN and 2200DN) it only works with PS files!!!

I _have to_ use enscript for TEXT files and pdf2ps for PDF files. I don't mind, since that's what I should do anyway from a standard Unix box, but I'm a bit puzzled...

[ Reply to This | # ]
Doing something wrong
Authored by: bbc on Feb 12, '02 04:28:10PM

I have tried these tips, but can't get it to work
I've copied the printcap example from this article verbatum, except for the location of lpd-hack.
I've used the pdf conversion script listed in the last reply, again verbatum.
I get no errors, even after entering the lpr command. After trying to print,
I use lpq to view the queue, and this is the result I get:

Warning: unable to get official name for remote machine stylus color 740 Warning: no daemon present
Rank Owner Job Files Total Size
1st root 0 /billscrap/test 15 bytes

lpq: lp: unknown host stylus color 740

My stylus color 740 is attached by a USB port. I don't have the device /dev/usblp0 created.
Any thoughts?
Thanks in advance,

[ Reply to This | # ]
combining hints
Authored by: on May 03, '02 03:06:34PM
Could any of you savvy unix people combine this hint with this hint and provide a way of sharing a nonpostscript printer over lpr by using Ghostscript. this would be great in an education setting where we will have several pre OSX macs around for quite a while yet. The Laserwriter driver with the Desktop printer utility would allow a desktop printer to print to such a printer you would just have to tweak a PPD so it would have the right options in it. Any takers?

[ Reply to This | # ]