Tuesday, May 19, 2009

Add a printer via command line

Original post located at: http://www.macosxhints.com/article.php?story=20061203221317612
Submitted by anonymous on macosxhints.com

Adding and Removing a Printer


This is done via the lpadmin command. To add a printer, use this format:
lpadmin -p Printer_Name -L "Printer Location" -E -v lpd://x.x.x.x
-P /Library/Printers/PPDs/Contents/Resources/en.lproj/Printer_Driver.gz

Don't use spaces in the Printer_name. "Printer location" can be anything.
An IP address belongs in the x.x.x.x bit, and change lpd: to ipp: if that's what you use.

To remove a printer:

lpadmin -x Printer_Name

To find out what printers are installed -- this one is great for
finding the names should you need them with the command above -- simply
use this:

lpstat -p

If you want to see the current jobs
on a computer, simply use this command. (Note that this will show the
jobs for the specified printer. However, if you do not specify a
printer, it will show the jobs for all queues.)

lpstat -o Printer_Name

To clear a queue of all jobs, we use lprm.
Note in this example the first hyphen is solo. This forces all jobs to
be cleared; more methods to clear individual jobs or those of a
particular are explained in the man page.

lprm - -P Printer_Name

Clearing all queues

Unfortunately I could not find a command which removed all jobs from
all queues. So I wrote up a small script which does this for you. You
could deploy this as a shell script file and then execute it (good for
both SSH and ARD), or in the case of Apple Remote Desktop's "Send UNIX
Command" function, simply throw in the whole script and run it as root.
#!/bin/bash

lpstat -p | awk '{print $2}' | while read printer
do
echo "Clearing Queue for Printer:" $printer
lprm - -P $printer
done

------end post-------

No comments: