Adding Printer to Mac via Terminal command line for AirPrint

cpominville
Contributor

Before I make my first ever post, I checked to see if anyone else has posted this. I did not see anything. Hopefully I searched correctly.

I can add printers to my Macs, using the Terminal command line, or create a script in Jamf to add the printers. Same result.

Here is an example of the command.

lpadmin -p Tech_Room_55_Printer -L "Tech Room 55" -E -v lpd://10.100.105.92 -P /Library/Printers/PPDs/Contents/Resources/HP Color LaserJet M651.gz -o printer-is-shared=false

I don't think I need to explain the contents of that command to any of you. Except to say, I want to add a Xerox printer in this case that uses AirPrint. I am connecting Macs, not iOS. When I add the printer manually, using the IP address, I end up with a default printer icon. When I use AirPrint, I get the full icon that represents the actual printer.

My question is, how would I add a printer using a command line and tell configure it with AirPrint.

I will keep tinkering.

16 REPLIES 16

theguvnor
New Contributor III

From https://medium.com/@hammen/significant-changes-in-macos-10-15-catalina-of-interest-to-mac-admins-fbc3865c055e item 24:

“lpadmin: Printer drivers are deprecated and will stop working in a future version of CUPS”. man lpadmin on a macOS Catalina system for more details. It seems that Apple wants admins to move from lpd/smb/socket (JetDirect) to AirPrint."

Given this deprecation of lpadmin's use of PPD / printer drivers in macOS 10.15, it seemed a good time to bring @cpominville's thread back up.

Does anyone have experience of Jamf / command line setup of printers via AirPrint?

joshuasee
Contributor III

Good news: I'm giving a presentation on printer management in a few weeks, so I've got some experience with it, and have been working on writing it up!

If you just want to use the AirPrint driver on a printer with a reliable DNS name or IP address, use the model switch in lpadmin instead of a PPD path, and choose the IPP Everywhere driver.
lpadmin -P SomeAirPrinter -D "Some AirPrint Printer" -E -v ipp://example.com/queuename -m everywhere

If you're in a situation where you must specify a path to a PPD file, it hides out in the Application Services framework, and has for several major OS version now, so its not likely to go anywhere.
lpadmin -P SomeAirPrinter -D "Some AirPrint Printer" -E -v ipp://example.com/queuename -P /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/Resources/AirPrint.ppd

If you're in a situation where you don't have fixed network toopology and must use dnssd, you should really rethink your network management, but the sequence of steps is:
1. Find the AirPrint printer URL with lpinfo -v. Pick one of anything starting dnssd:// .
2. Use the dns-sd command to retrieve the TXT record from the advertisement for the dnssd URL.
3. Use you preferred text parser to pull out the UDID for the printer.
4. Append the UDID to the dnssd URL, and use that with lpadmin and the IPP Everywhere driver.
lpadmin -P SomeAirPrinter -E -V dnssd://Some%20Air%20Printer._ipp._tcp.local./?uuid=0123abcd-4567-efab-cd890123efab -m everywhere

The ippfind command provides a somewhat easier way to get a working local queue, albeit not exactly equivalent to the way AirPrint does it.
1. Run ippfind. No arguments needed since they defaults are fine.
2. Add the queue with the resulting URL and IPP everywhere driver
lpadmin -p SomeAirPrinter -E -v $(ippfind | head -1) -P /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/Resources/AirPrint.ppd
Do not use the above command in production since you can't trust the queue names will always appear in the same order in ippfind.

Bad news: I'm giving a presentation on printer management in a few weeks, and stuff has changed! I'm not going to have the time to do thorough testing with Catalina. The audience will not be pleased. Anybody have recommendations on paintball masks or techniques for removing tomato and rotten fruit stains from clothing?

martin
Contributor II
Contributor II

Hi @joshuasee,

Thanks for sharing, great info!

Have you noticed the command ipp2ppd? That tool is being used by the GUI and can be using using cli:

$ /System/Library/Printers/Libraries/ipp2ppd ipp://1.2.3.4/ipp/print "" > /private/tmp/printer_driver.ppd

Than use the lpadmin command to install the printer (and you get a nice icon too!):

$ lpadmin -p "printer_name" -D "Printer Name" -v ipp://1.2.3.4/ipp/print -P /private/tmp/printer_driver.ppd

More info about ipp2ppd

cpominville
Contributor

HI Joshuasee

Thanks so much for the info. I have not had a chance to review it closely till today.

Your first command of..... lpadmin -P SomeAirPrinter -D "Some AirPrint Printer" -E -v ipp://example.com/queuename -m everywhere

Will this work for a print queue in a windows environment?

Here is what I tried

carol@Carols-iMac-2 ~ % lpadmin -P Salle55 -D "Salle 55" -E -v ipp:ss-service -m everywhere lpadmin: Unable to query printer: Unknown
carol@Carols-iMac-2 ~ % lpadmin -P Salle55 -D "Salle 55" -E -v ipp:csdcab.on.cass-service -m everywhere
lpadmin: Unable to query printer: Unknown
carol@Carols-iMac-2 ~ % lpadmin -P Salle55 -D "Salle 55" -E -v ipp://csdcab.on.ca/ss-service -m everywhere
lpadmin: Unable to connect to “csdcab.on.ca:631”: Operation now in progress
carol@Carols-iMac-2 ~ %

csdcab.on.ca is our domain and ss-service is the queue. This may not be possible.

At the time of this writing I have not tried just direct to the printer yet with AirPrint. Living in a windows world, just complicates everything!

Gonna try direct to the printer now.

cpominville
Contributor

trying direct to the printer today

Here is your command lpadmin -P SomeAirPrinter -D "Some AirPrint Printer" -E -v ipp://example.com/queuename -m everywhere

Here is what I tried ...I am missing something..

carol@Carols-iMac-2 ~ % lpadmin -P AirprintSAlle55 -D "Airprint Salle 55" -E -v ipp://10.100.105.92/Airprint Salle 55 -m everywhere
lpadmin: Bad printer URI “ipp://10.100.105.92/Airprint Salle 55”.
carol@Carols-iMac-2 ~ % lpadmin -P AirprintSAlle55 -D "Airprint Salle 55" -E -v ipp://10.100.105.92/AirprintSalle55 -m everywhere lpadmin: Unable to set the printer options: You must specify a printer name first.
carol@Carols-iMac-2 ~ % lpadmin -P AirprintSAlle55 -D "Airprint Salle 55" -E -v ipp://10.100.105.92 -m everywhere
lpadmin: Unable to set the printer options: You must specify a printer name first.
carol@Carols-iMac-2 ~ %

mainelysteve
Valued Contributor

@cpominville Try a lowercase p in your command. Since you're not specifying a PPD file the uppercase P in the beginning portion of that command won't work.

cpominville
Contributor

Thanks mainelysteve!!! Worked immediately. Knowledgeable people like you I admire! Need some bass guitar lessons? With AirPrint, I should still be able to get the Icon for the printer, and not the generic icon...no? At present, I have the generic icon. No worries, if your busy. I'll keep plugging away.

mainelysteve
Valued Contributor

You're using the IPP everywhere driver as mentioned by @joshuasee above. It's a generic driver so the printer icon and settings won't be specific to the device. AirPrint still searches for and installs a manufacturer "driver" and will use the everywhere driver in other cases.

Ludeth
New Contributor II

Hey @mainelysteve @joshuasee what would one do for printers that are hosted out of a Windows queue in a very large corporate print anywhere type solution? We don't use IPP for those. We install them with lpadmin using:

smb://myPrinterServer/myPrintQueue

mainelysteve
Valued Contributor

@Ludeth Do you have a method of broadcasting AirPrint queues to clients? Windows Server alone won't help with this. If you use Papercut in your environment then their Mobility software can help with that. Others may chime in with different ideas as well.

Additionally If you're using kerberos tickets or a un/pw prompt on the first print job then you'll need to adjust your environment i.e. enterprise connect, SSO/Kerberos profile(10.15+) or Nomad. If you bind your clients and they use mobile accounts or even network accounts that may be enough. If you don't have any specific permissions applied to the queues then this is a moot point.

mbracco
Contributor

Hi @joshuasee,
I have similar problems getting ipp queue together. May you help me out. We use HP Officejet Pro 8730 on cabked ethernet.
Do access the scan function correctly we need a valid queue. I cannot find much on dns-sd usage. How do you get the txt record and the udid ? lpinfo -v shows no dnssd printers. We mainly try to find the printer. They are dhcp configured and have a fixed hostname, so it should be possible to find them. a ping and nslookup work find. But i cannot get the ipp queue together,....

roodavis
New Contributor

@mainelysteve as you noted above @cpominville was still using the IPP Everywhere generic driver. Is there a significant difference between the Airprint driver and the IPP Everywhere driver? If so, how do you designate the Airprint driver. If I use -m airprint or -P with anything, I get the dreaded "May 29 2020 13:27:46 -0400 ERROR: Error: lpadmin: Printer drivers are deprecated and will stop working in a future version of CUPS" and my install script fails.

mainelysteve
Valued Contributor

@roodavis I don't believe there is any difference between the two, but I'm not a CUPS or printer expert by any means. I think the issue you're seeing is due to the uppercase P. Change it to a lowercase p and the command should go through.

joeharden
New Contributor II

I just tried using the -m everywhere option on a 10.15.6 machine and get this error:

lpadmin: Unable to create PPD file: File exists

No printer is installed. I even tried deleting all existing printers but still get the message.

roodavis
New Contributor

I am revisiting adding AirPrinter's via a script and noticing that when I add a printer via the GUI, then look at it in CUPS I get different information when I use IPP or AirPrint.

IPP gives me this:

Driver: KONICA MINOLTA C659 PS (color) Connection: ipp://10.23.16.126/ipp/print

AirPrint gives me:

Driver: KONICA MINOLTA bizhub C659-AirPrint (color, 2-sided printing) Connection: ipps://10.23.16.126/ipp/print

Printers added using IPP do not show all copier finishing options.
So far printers added using AirPrint shows all printer features including finishing options.

However, I can not figure out the proper syntax to get the AirPrint results in a terminal commandline or script.

Thoughts or suggestions?

mainelysteve
Valued Contributor

@roodavis That may be down the device (MFP or not) and whether it provides icons, finishing options, etc. IPP everywhere will not since it's a generic driver. My comment above about the two being similar was more or less tied to devices that don't provide that information or for instances where the AirPrint broadcasting was coming from software based sources, not the tree killer itself.