Add a printer via command-line in OS X

Goal: add a network printer via Remote Desktop’s command-line to numerous Macs.

The following commands have worked for me:

lpadmin -p "NAME" -v "URL" -P "PPD" -o printer-is-shared=false -E
cupsenable "NAME"
cupsaccept "NAME"

…where:

  • -E — enables the printer.
  • -o printer-is-shared=false — the added printers are shared by default (i.e. “Share this printer on the network” would be ticked). Since my printer is already shared on the network, I don’t want to share it again from the Macs.
  • NAME — arbitrary name, can be anything, e.g. “MyBadassPrinter”.
  • URL — the printer’s URL.
  • PPD — the path to a .ppd (PostScript Printer Description) file.

Probably you don’t know how to find the URL and the PPD of the printer.

The first step to retrieve them is to add the printer to your computer via System Preferences > Print & Scan.

Now let’s find the URL. What follows is probably not the best way to do it, but it’s worked for me. Run the following to enable CUPS web-interface:

cupsctl WebInterface=yes

In your web-browser open http://localhost:631/printers/, click on your printer’s name and copy the URL after “Connection”:

cups-connection

How to get the PPD? This is easier: go to /etc/cups/ppd/ and copy the PPD file. Obviously you’d want to put it on a local NAS or in some other place that would be accessible by other Macs.

The final command for me was:

lpadmin -p "AFFA-ST-MFP-1" -v "dnssd://AFFA-ST-MFP-1._ipp._tcp.local." -P "/Volumes/Servers/AFFA_ST_MFP_1.ppd" -o printer-is-shared=false; cupsenable "AFFA-ST-MFP-1" -E; cupsaccept "AFFA-ST-MFP-1";

Further reading:

This entry was posted in How to’s and tagged , . Bookmark the permalink.

8 Responses to Add a printer via command-line in OS X

  1. S says:

    Thanks for this guide – very helpful. Might be worth changing all the “PDD” references to “PPD” for clarity though :)

  2. Martin says:

    This looks good, can the PPD file part be omitted?

  3. John says:

    Our printers do not need PPD. Is it possible to add IPP printer without PPD?

  4. sr9 says:

    from lpadmin(8):

    When specified before the -d, -p, or -x options, the -E option forces encryption when connecting to the server.

  5. Todd says:

    Does anyone know the terminal command to add a printer to a mac that is already being shared on the network? I have an old mini that is sharing printers to everyone. We just replaced these printers with new ones. This mini (Print Server) is now updated and sharing these new printers.

    I know the terminal command how to erase all the current printers on each of our macs. But can’t figure out how to add these new printers from the Print Server using ARD and the unix command. Something like this????

    lpoptions -d dnssd://Canon%207565%20Front%20%40%20Print%20Server ( then some other commands??)

    • Todd says:

      This is as far as I got but still getting an error….

      lpadmin: Unable to open PPD “/Users/it/Desktop/C5550.ppd”: Unable to open PPD file on line 0.
      lpadmin: Unable to open PPD file “/Users/it/Desktop/C5550.ppd” – No such file or directory

      This was my latest attempt that failed…
      lpadmin -p Canon_C5550_Back -v dnssd://Canon%20C5550%20Back%20%40%20Print%20Server._ipp._tcp.local. -E -D ‘Canon C5550 Back’ -L 192.168.41.7 -P /Users/it/Desktop/C5550.ppd

Leave a Reply

Your email address will not be published. Required fields are marked *