Having recently been asked to install printers to a bunch of macOS users remotely, this got me thinking; How can this be automated via shell script?
A simple script should be easy enough to create a printer, link a driver and assign the IP address. The same script should then be able to be manipulated to remove it if required.
So heres the script:
sudo /usr/sbin/lpadmin -p “printer name” -E -v lpd://”printer IP/hostname”/”queue name” -P “path to PPD file” -D “printer description”
sudo /usr/sbin/lpadmin -p FMPMAC -E -v lpd://”printsyd.ffp.jfp.com.au”/”FMPMAC” -P /Library/Printers/PPDs/Contents/Resources/FX\ ApeosPort-IV\ C4475\ PS.gz -D FMPMAC -o printer-is-shared=false
The above script will only work if you have the printer drivers already installed. In my organisation we’re using LANDesk Management Suite, which can push out and install the drivers ahead of time, or when provisioning devices.
In the case where you need to copy the files manually, This is also done via a script:
sudo cp -R /Volumes/FMPMAC/FX\ ApeosPort-IV\ C4475\ PS.gz /Library/Printers/PPDs/Contents/Resources\
In the instance that you need to remove the printer, simply change the first -p with a -x
You can find the printer configurations in a web browser using the CUPS web-interface, to enable this run the following command in terminal:
Then open a web browser and navigate to http://localhost:631/printers/ click on the printer’s name and you can then see the URL and driver information.
-p : configures printer
-E : enables printer to accept print jobs
-v : Assigns printer URL
-P : specifies a ppd file to use
-D : creates a text description for the printer