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

Managing multiple printers via the command line Printers
Working on a site with a few hundred OS X machines, manually altering each computer's configuration can become very tedious, very fast. Especially when dealing with printers. I had issues whereby I would sometimes need to set up a number of computers with a new printer, and then remove it later. Add to that, I have printers constantly spitting things out because people hit Print a few too many times and clog up the queues. Fortunately, I managed to come across a few Unix commands which, using ssh or ideally Apple Remote Desktop (via the ever-useful 'Send UNIX command' function), can reduce jobs of many minutes, even hours, into seconds.

Read on for some of the tricks I use...

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
All you have to do to the above is adjust the settings as necessary. Unfortunately, the tradeoff here is that you can't use spaces in the Printer_name, tleast from what I can determine. "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. I'm unsure about other protocols, but perhaps the man page can tell you much more about this command. Last of all is the driver. Before using the command, you'd be best to look in the directory shown and find the filename, and then replicate it in the command line. If you're lazy you could always just drag the PPD file over to the Terminal window, too!

To remove a printer, it's a far simpler affair. Simply:
lpadmin -x Printer_Name
Queue Management

Nothing is more annoying than a printer, well, printing things, when people have walked away leaving nothing but a big pile of print jobs behind. And the last thing anyone should have to do is find and clear all printer queues manually. Thankfully, this too is easily resolved. Here are just a couple of commands I've found very helpful; I'm sure there are more if you go looking.

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.

lpstat -p | awk '{print $2}' | while read printer
  echo "Clearing Queue for Printer:" $printer
  lprm - -P $printer
And that's that! Throw it at all of the computers under your wing, and hopefully you'll reduce waste, headache, and get to go home early for a change!
  • Currently 2.45 / 5
  You rated: 1 / 5 (11 votes cast)

Managing multiple printers via the command line | 10 comments | Create New Account
Click here to return to the 'Managing multiple printers via the command line' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Managing multiple printers via the command line
Authored by: ocdinsomniac on Dec 07, '06 10:00:04AM

This is a great hint. Thanks!

Coincidentally, I recently had the need to add and remove printers to a lab full of Macs. I sure wish I'd known about these commands. But I thought I'd share my method, which is completely different, but which also works well, and is pretty easy.

1. Set up one system with all printers, exactly as you'll want them on the other machines.
2. Copy the entire /etc/cups folder to the other machines.
3. Restart the cups daemon (as root): killall -HUP cupsd
4. (Optional) If you have network users, restart Directory Services (as root): killall DirectoryService

That should do it.

Also, the command I use to kill all print jobs is: cancel -a -


[ Reply to This | # ]
Managing multiple printers via the command line
Authored by: mbd on Dec 07, '06 02:27:01PM
If you're using a whole lab of machines, you may want to try and use scripting to configure the machine's printers. I found this set of scripts a while ago and modified it as needed for our environment. I can now configure any number macs' printer configurations on the fly without difficulty. Additionally, in regards to clearing printer queues, the way I do that to be 100% sure that it's really going to do it is to add a LoginHook to each machine so that every time a user logs in, the following script is run, which clears out the CUPS server's queues and restarts it. Works brilliantly, and haven't had a report of a blocked print queue on a mac since :-).

# --cut--
rm -fr /var/spool/cups
mkdir /var/spool/cups
mkdir /var/spool/cups/tmp
chmod 710 /var/spool/cups
chmod 1770 /var/spool/cups/tmp
chown -R root:lp /var/spool/cups
killall -HUP cupsd
# --cut--

[ Reply to This | # ]
Managing multiple printers via the command line
Authored by: Rake on Dec 07, '06 05:07:04PM
Yes, I later found that the crude script I wrote above doesnt' quite work when it processes unexpected input, eg when printer queues are paused. Then I discovered the cancel -a command which makes it redundant anyway. mdb - Ta! I've been looking into scripts. I will probably whip up a LogoutHook to clear jobs when users are finished whatever they're doing and logout.

[ Reply to This | # ]
Managing multiple printers via the command line
Authored by: mlc on Dec 23, '06 09:37:09PM
Thanks for the tip. I've found that if you use the -D flag (description), you can have a name that includes spaces. If the description is set, then the printer will show up in OS X with that name instead of the formal name. I've revised the the script to include checking for the printer prior adding, and to include a few HP LaserJet print options as well. Hope this helps.


# Tests to see if printer exists - sidesteps a variable scope issue
# Requires the printer name as a parameter.  Returns 1 if the printer exists.
function printerExists()
  if [ $# -ne 1 ]; then
    echo "Incorrect parameters"
    return 0
    lpstat -p | awk '{print $2}' | while read printer
      if [ $1 = "${printer}" ]; then
        return 1

# Printer Name cannot Include any spaces
# User friendly printer name"
prDescription="Printer Name"
# Location
prLocation="Home Office"
# IP Address of printer
# PPD Filename... assumes it is installed on machine
prPPD="HP LaserJet 2200.gz"

#Test If Printer is already installed
printerExists $prName

if [ $prExists -eq 1 ]; then
  echo "Printer already exists. Skipping: \"$prName\""
  # Add Printer Command 
  lpadmin -p "${prName}" -D "${prDescription}" -L "${prLocation}" \
  -E -v lpd://"${prAddress}" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/$prPPD" \
  -o HPOption_Duplexer=True -o Resolution=1200x1200dpi

[ Reply to This | # ]
Managing multiple printers via the command line
Authored by: mikerose on Jan 18, '07 01:35:44PM

Woohoo! This is great! I was able to research the correct options for my Canon machines via lpoptions -v ... and I'm now a printer-configuring machine. :-)

[ Reply to This | # ]
Anyone done this with Canon copiers?
Authored by: mikerose on Feb 05, '07 07:54:44AM

I may have spoken a bit too soon. My setup works perfectly with this script except for

lpoptions -d "MyCopier" -o EFFinisher="Finisher"

The machines in question are Canon 8070 copiers with the ImagePASS S1 RIP, which supports an option of "Finisher" for the K1 finisher unit. Although this is what shows up when you read the options from a manual configuration (via Printer Utility), it doesn't work the other way: setting it up from the command line doesn't show the finisher options in the Print dialog. :-(

any help appreciated.

[ Reply to This | # ]
awesome tip - how to set as default?
Authored by: chrisrosa on Jan 08, '07 11:08:29AM

Hi...thanks so much for this tip. I still haven't found a way to set the new printer as the user's default. I thought perhaps the lpadmin -d flag would do it, but (at least) the Printer Setup Utility doesn't think the default has changed. Any ideas? Thanks again.

[ Reply to This | # ]
awesome tip - how to set as default?
Authored by: apta on Mar 16, '07 05:38:46PM
To set a default printer, add the following line to the above script after the lpadmin command:

  # Set Printer as Default
  lpoptions -d "${prName}"

[ Reply to This | # ]
Authored by: lucidsystems on Mar 20, '07 07:27:10PM

Great article!

Lucid has put together a free, open-source tool called PrinterSetup.

It would be great to bundle the information in this article with PrinterSetup?

Please consider creating a *NIX command line print queue management document and formally submitting this to Lucid for inclusion into the PrinterSetup project.

FYI : PrinterSetup supports setting a default printer. However if you would like to set the default printer using the command line with a tool such as ARD then the following command should help :

$ lpoptions -d cupsqueuename

Further details are available within the lpoptions man page, kindly hosted by HMUG.

All the best from, the Lucid Information Systems Team.

[ Reply to This | # ]

PrintingWorks : Updated
Authored by: lucidsystems on Jul 23, '07 03:50:42PM

PrinterSetup is now a component of PrintingWorks,
the open-source cross-platform print accounting solution.

The latest version of PrinterSetup features, scripts which :

  • Cancel all jobs on all print queues.
  • Start all print queues.

Screen casts are now available to help you get started
with PrinterSetup.

The Lucid Team.

Lucid Information Systems
Information Processing, Storage and Backup

Save some trees and with a print accounting system.

[ Reply to This | # ]