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.

Disclaimer:

The sample scripts provided below are adapted from third-party open-source sites.

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.

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.

Printer setup on macOS System Preferences/Settings using scripts

Once the setup printer script is executed, the printer will be added under System Preferences/System Settings > Printers & Scanners.

Notes:


You can obtain the printer’s configuration settings using the lpoptions command.

  1. Open Terminal on a macOS device connected to the given printer.
  2. Type lpoptions.
  3. Press enter.
  4. It displays the printer’s details.


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

-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.

Action History of a Mac after setting up printers to be removed using scripts

You can confirm the script execution by checking the status “Printer added successfully” and “Printer Removed Successfully” in the Output.

Action History of a Mac after setting up printers to be added using scripts

Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository