Install Airprint printer on macOS HighSierra with lpadmin command


On HighSierra i can add a new printer with the GUI in the Standard tab either as "Bonjour with AirPrint or Secure Airprint"  or in the IP tab as "Airprint with Airprint". How can I do the same with lpadmin?
So far I figured out:

lpadmin -E -p NewPrinter -v ipp://... -D "Description" -L "Location"

but something's missing. I assume -P and/or -m. But I don't know what arguments to use with these options.

Does anyone know?

TuliTaivasserver adminAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I would use -P and specify the location of the printer's PPD file. The PPD (PostScript Printer Description) file tells the OSX PostScript driver what the printer's capabilities are (duplexing, colour, trays, etc) and the PostScript commands to use them.

Do you have the PPD file for your printer? Is it a PostScript printer? What model?
TuliTaivasserver adminAuthor Commented:
The printer is an HP Color LaserJet Enterprise CP5525dn.  The point is, I don't want to use the ppd from HP  because of some problems with High Sierra (offending command xshow).

When I add a new printer in the GUI and go to the IP tab, enter the printer's IP and select "Airprint" as the protocol, the "Use." field at the bottom of the dialog box, where I normally would select the printer model, is preset with "Airprint".
However there is no "Airprint" ppd in /Library/Printers/PPDs/Contents/Resources/ so I don't know what file to use after -P.
I maybe could use the ppd that is created in /etc/cups/ppd when I add a printer with the GUI as mentioned above. But that means I have to copy the file to all machines I want to install that printer with the lpadmin command (either by ssh or remote desktop) which I want to avoid if possible.
According to this Apple support document, the CP5525is not supported through Airprint. However, you should be able to connect to it fine using LPR.

PPDs do not depend on the connection method. They don't even depend on the OS. A Windows PPD will work just fine under OSX, or vice versa. A PPD file is a text file that can be used with a PostScript driver under any architecture.

OSX may ship with a PPD fr your printer, but the HP one should also work. The PPD file can be installed in any convenient folder. I does not have to be under /Library/Printers/PPDs. You can even have it on a server.
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

TuliTaivasserver adminAuthor Commented:
In this HP document our printer is listed under the heading "HP ePrint and Mobile printing-capable printers" which, as far as I understand, includes Airprint.

In any case, Airprint is what the GUI puts itself into the "Use:" box after checking the printer's capabilities, so I assume it must have found the printer to support that.
But if I select LPD as the protocol, the GUI selects the printer specific ppd and not Airprint and there's also no way to select Airprint manually. So protocol and Airprint seem somehow related, albeit what you say is certainly correct with respect to a ppd just being a text file and basically independent of the OS. But then again a printer installed as Airprint has fewer options than one with the printer specific ppd.

Basically I'm looking for a way to mimic with a command line tool (maybe not lpadmin?) the addition of a printer in the GUI as Airprint.

For what it is worth, what follows are the first lines of the printer specific ppd and the Airprint ppd in /etc/cups/ppd

printer specific:
*PPD-Adobe: "4.3"
*% =======================================================
*% © Copyright 2008-2013, 2015 HP Development Company, L.P.
*% PPD Version for OS X
*% =======================================================
*FormatVersion: "4.3"
*FileVersion: "19.13"

*LanguageVersion: English
*cupsLanguages: "da de es fi fr it ja ko nl no pt ru sv zh_CN zh_TW"
*LanguageEncoding: ISOLatin1
*PCFileName: "HP5220.PPD"
*cupsVersion: 1.3
*%== Mac OS X specific begin ==
*APDialogExtension: "/Library/Printers/hp/PDEs/hpPostScriptPDE.plugin"
*HPPDEPanel: "HPColorOptionsPanel"
*HPPDEPanel: "HPFinishingPanel"
*HPPDEPanel: "HPWatermarks"

*cupsFilter: "application/vnd.cups-postscript 0 /Library/Printers/hp/filter/hpPostProcessing.bundle/Contents/MacOS/hpPostProcessing"
*%APPrinterUtilityPath: "/Library/Printers/hp/Utilities/HTTP over USB/"
*%*APScanAppBundleID: "com.hp.laserjet.scan"

*cupsICCProfile RGB../sRGB Matching Profile: "/Library/Printers/hp/Profiles/sRGB_A.icc"
*cupsICCProfile CMYK../CMYK Matching Profile: "/Library/Printers/hp/Profiles/CMYK_A.icc"
*cupsICCProfile Gray../Gray Matching Profile: "/Library/Printers/hp/Profiles/Gray_A.icc"

*APPrinterIconPath: "/Library/Printers/hp/Icons/HP Color LaserJet CP5220d Series.icns"

*APPrinterPreset ChartsAndGraphs/Charts & Graphs: "
      *HPTextNeutralGrays Black
      *HPPhotoNeutralGrays Black
      *HPGraphicsNeutralGrays Black General"
*da.APPrinterPreset ChartsAndGraphs/Diagrammer og grafik: ""
*de.APPrinterPreset ChartsAndGraphs/Diagramme & Grafiken: ""
*es.APPrinterPreset ChartsAndGraphs/Cuadros y gráficos: ""
*fi.APPrinterPreset ChartsAndGraphs/Kaaviot ja grafiikka: ""
*fr.APPrinterPreset ChartsAndGraphs/Diagrammes et graphiques: ""
*it.APPrinterPreset ChartsAndGraphs/Diagrammi e grafici: ""
*ja.APPrinterPreset ChartsAndGraphs/グラフと図: ""
*ko.APPrinterPreset ChartsAndGraphs/차트 및 그래픽: ""
*nl.APPrinterPreset ChartsAndGraphs/Tabellen en grafieken: ""
*no.APPrinterPreset ChartsAndGraphs/Diagrammer og grafikk: ""
*pt.APPrinterPreset ChartsAndGraphs/Tabelas e gráficos: ""
*ru.APPrinterPreset ChartsAndGraphs/Диаграммы и графики: ""
*sv.APPrinterPreset ChartsAndGraphs/Diagram och grafik: ""
*zh_CN.APPrinterPreset ChartsAndGraphs/图表和图形: ""
*zh_TW.APPrinterPreset ChartsAndGraphs/圖表和圖形: ""

*%== Mac OS X specific end ==

*% Product Name and Version Information
*Manufacturer:      "HP"
*Product: "(HP Color LaserJet CP5225dn)"
*Product: "(Hewlett-Packard HP Color LaserJet CP5225dn)"
*Product: "(HP Color LaserJet CP5221dn)"
*Product: "(Hewlett-Packard HP Color LaserJet CP5221dn)"
*Product: "(HP Color LaserJet CP5223dn)"
*Product: "(Hewlett-Packard HP Color LaserJet CP5223dn)"
*Product: "(HP Color LaserJet CP5227dn)"
*Product: "(Hewlett-Packard HP Color LaserJet CP5227dn)"
*Product: "(HP Color LaserJet CP5229dn)"
*Product: "(Hewlett-Packard HP Color LaserJet CP5229dn)"
*ModelName:      "HP Color LaserJet CP5220 Series"
*ShortNickName: "HP Color LaserJet CP5220 Series"
*NickName:      "HP Color LaserJet CP5220 Series with Duplexer"
*PSVersion: "(3011.001) 1"



*PPD-Adobe: "4.3"
*% PPD created by ipp2ppd (v2:Feb  6 2017)
*FormatVersion: "4.3"
*FileVersion: "2.0"
*LanguageVersion: English
*LanguageEncoding: ISOLatin1
*PSVersion: "(3010.000) 0"
*LanguageLevel: "3"
*FileSystem: False
*cupsVersion: 2.0
*cupsModelNumber: 0
*cupsSNMPSupplies: False
*APAirPrint: True
*APAirPrintVersion: 1.5
*APURFVersion: 1.4
*APPrinterFWVersion: "HP Color LaserJet CP5520 Series:2308937_578508"
*cupsLanguages: "en"
*cupsIdentifyActions: "flash display"
*APPrinterIconPath: "/Library/Printers/Icons/HP Color LaserJet CP5520 Series.icns"
*APAcceptsMixedURF: True
*ModelName: "HP Color LaserJet CP5520 Series"
*Product: (HP Color LaserJet CP5520 Series)
*ShortNickName: "HP Color LaserJet CP5520 Series"
*Manufacturer: "HP"
*NickName: "HP Color LaserJet CP5520 Series-AirPrint"
TuliTaivasserver adminAuthor Commented:
Maybe this page helps understanding what I mean. See last section "Configure AirPrint on a Mac computer".
Does lpadmin even support Airprint? It's intended for support of lpr/lpd printing.
TuliTaivasserver adminAuthor Commented:
I have no idea. That's why I'm asking. Mayby it can't be done that way.
I'm beginnimng to think we're trying to shoehorn lpadmin into something it wasn't designed for. I found this site which lists the ports used by Airplay services. The only familiar one for printing is 9100. It is known under several names, such as "raw" or "appsocket". Sometimes it's called "JetDirect" - even though it was not invented by HP and is not limited to their network cards.

As far as I know, lpadmin is designed to use port 515 (lpd). However, on the assumption that Airprint will connect to port 9100, I have also found one web page that uses the -o option:

lpadmin -p luna1 -o dest=nimquat:9100 -o protocol=tcp

This particular use of -o (for Solaris) is not listed in the lpadmin man page. An Apple support page lists the -v option, which does appear in man:

lpadmin -p skippy -v socket:// -P "HP LaserJet 4000 Series.gz"

Give this a try; if it doesn't work we'll have to assume that lpadmin is the wrong tool for the job. I have been unable to find any document that states lpadmin supports Airprint.
TuliTaivasserver adminAuthor Commented:

Thanks for your suggestions and your input.

I made some progress, i think. A pointer was the Line "*% PPD created by ipp2ppd (v2:Feb  6 2017)" in the ppd the Air Print printer uses.

So when I set up an Air Print printer with the GUI I believe this is what happens:

- The GUI calls the tool ipp2ppd (in /System/Library/Printers/Libraries) with the uri of the printer (ipp(s) or dnssd) and the printer specific pdd (presumably from /Library/Printers/PPDs/Contents/Resources) as parameters and saves the output to a Air Print ppd file in /etc/cups/ppd named the same as the printer. I havent checked the differences yet. The Air Print ppd is normally shorter.
- an .icns file is created in /Library/Printers/Icons. I haven't found out where that icon is copied from. It's a different icon than the one in /Library/Printers/hp/Icons
- the line '*APPrinterIconPath: "/Library/Printers/Icons/..."' is added to the ppd created in the first step
- the printer is installed

So to do that from the command line
- i have to copy the generated Airprint ppd to the target machine or to an accessible share (as you mentioned above) or generate a new one with the ipp2ppd tool and add the "APPrinterIconPath..." line
- i have to copy the icon or adapt the APPrinterIconPath
- i run lpadmin -p "printer name" -E -v "ipp: or dnssd: uri" -P "path to the Air Print ppd" -D "name of the printer in the printers list" -L "location"

I haven't found a way to add the *APPrinterIconPath information with an -o option of the lpadmin command.

I haven't done extensive tests but I was able to print a page.

Great news. Adding the *APPrinterIconPath line to the PPD should be possible with something like sed.

If you think the problem is fixed, make sure you accept your own answer as the solution!
TuliTaivasserver adminAuthor Commented:
The mystery of the new printer icon is solved (at least with one printer model): the GUI asks the printer for images in various resolutions

(from wireshark):
180      47.813176   x.y.z.222   x.y.z.206   HTTP   212   GET /hp/device/printer48.png HTTP/1.1
200      47.897840   x.y.z.222   x.y.z.206   HTTP   213   GET /hp/device/printer128.png HTTP/1.1
225      47.950259   x.y.z.222   x.y.z.206   HTTP   213      GET /hp/device/printer512.png HTTP/1.1

and builds a new icns file. I can't trace file creation and access (opensnoop or, though, because of system integrity protection (and turning SIP off is too cumbersome).

you can look at these pics in the printer with a browser.
No idea whether these names are standardized across printers. A short test of another HP printer model with the browser indicates they are not.
TuliTaivasserver adminAuthor Commented:
will summarize the whole project and try to write a script but it might take a few days before I can post it here.
TuliTaivasserver adminAuthor Commented:
At the moment for me the best option seems to install the printer on my staging mac with the GUI and copy the generated icns file and the PDD to the machines I want to install the printer on and use the lpadmin command like

lpadmin -p "printer name" -E -v "ipp: or dnssd: uri" -P "path to the Air Print ppd" -D "name of the printer in the printers list" -L "location"

Of course the path to the icns file in the PDD must match the actual location and the name of the PPD must match the name of the printer given as the -p option.

If one wants to do it from scratch this is what I have found so far:
As explained above the icns file is genereated from pngs that the GUI downloads from the printer. To know what files to download, the GUI sends an ipp request to the printer and in the response among other things there is is an attribute printer-icons which is an array of the locations of the images of different sizes which then are downloaded with http get.

Next step is to get the size of the images and rename them like icon_widthxheight.png and put them into a folder whose name must have the extension .iconset. Then one can use iconutil to generate the icns file. This is as per

However, my first problem is that I don't know how to use the ipptool shell command to query the printer so that it gives me the printer-icons attribute in a way I can use to pass it to wget to download the printer images. I have adapted the get-printer-attributes.test file and I can see with wireshark that the ipp-response is sent back but in the shell nothing is output. I can divert the output to a plist file but then I would have to find out how to read that (ok, probably easy with defaults read, now that I come to think of it).
Secondly I don't know how to get the image dimensions from a downloaded png to rename the file properly.
The third problem is that I have no clue how I can make sure that I select the proper pdd to feed to ipp2pdd (see above).
So all in all it seems easier for me to just copy the files that the GUI creates. And also I don't have the time to dig into that right now.

But if anyone more knowledgable that me takes it up from here and finishes this job, others might be greatful.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TuliTaivasserver adminAuthor Commented:
Another piece of the puzzle. The size of an image can be found with sips. To build the required name for one of the downloaded printer icons that goes into the iconset I use this command (probably there are smarter ones)

filename=<path to image>
iconname=icon_`sips -g pixelWidth "$filename" | tail -n1 | cut -d" " -f4`x`sips -g pixelHeight "$filename" | tail -n1 | cut -d" " -f4`
TuliTaivasserver adminAuthor Commented:
time permitting I will research the missing steps and provide more information. In the meantime I chose my own solution as best to close this question.
TuliTaivasserver adminAuthor Commented:
here's the ipptool command to query the printer for the path to the printer icons that works for me:

ipptool -tv ipp://<dns name or IP>/ipp/print get-printer-attributes.test | grep printer-icons
Answer:  printer-icons (1setOf uri) = http://<IP>/hp/device/printer48.png,http://<IP>/hp/device/printer128.png,http://<IP>/hp/device/printer512.png
Great work TuliTaivas! Thanks for the points, but the credit's all yours.
TuliTaivasserver adminAuthor Commented:
it's the only solution provided and it works
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Printers and Scanners

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.