Category filter
Script to set up Printers on macOS devices
Managing multiple printers is a critical task for IT admins in a corporate setting. Deploying network printers on managed macOS devices is a two-step procedure using scripts. Initially, you need to gather the wireless printer configuration settings and use the details to create a corresponding script. Then, you can execute the script remotely using Hexnode’s Execute Custom Script feature.
Script to deploy printers on Mac
With this script, IT admins can effectively deploy multiple Wi-Fi, Bluetooth, and Network printers across all macOS devices.
1 2 3 4 5 |
#!/bin/bash lpadmin -p <destination> -E -D <destination> -v <device_uri> -m everywhere echo "Printer added successfully" |
lpadmin is a built-in command for macOS that is used to manage printers. The script uses the following parameters along with the lpadmin command.
-p
specifies the destination name or identifier you assigned for the printer.
-E
enables the printer to be immediately active and ensures it is ready to accept jobs.
-D
specifies a descriptive textual description and display name for the printer to be identified.
-v device_uri
specifies the connecting path (device URI) for the printer (eg: usb://HP/LaserJet%201100, ipp://192.168.1.100/ipp/print, bluetooth://Printer_Name).
-m
configures the printer to be compatible with IPP Everywhere. It ensures a universal printing protocol for a wide range of devices.
You can also define other printer settings to be applied on macOS devices using the lpadmin command. Type in the command lpadmin in the Terminal to retrieve its entire attribute list.
Once the setup printer script is executed, the printer will be added under System Preferences/System Settings > Printers & Scanners.
The value listed along with the printer-info corresponds to the destination. The device_uri will be displayed next to the key device-uri.
Script to remove printers from Mac
1 2 3 4 5 |
#!/bin/bash lpadmin -x <destination> echo "Printer Removed Successfully" |
-x destination
specifies the printer destination to be removed from the device.
If the remove printer script is executed, the printer will be removed from System Preferences/System Settings > Printers & Scanners.
Output
You can monitor the script’s real-time status and output using the Action History tab.
You can confirm the script execution by checking the status “Printer added successfully” and “Printer Removed Successfully” in the Output.