# 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](https://www.hexnode.com/mobile-device-management/help/how-to-run-scripts-on-mac-using-hexnode-mdm/) 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.

Sample script to deploy printer on Mac

\#!/bin/bash lpadmin -p <destination> -E -D <destination> -v <device\_uri> -m everywhere echo "Printer added successfully" 

   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 <destination></destination>` 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 <destination></destination>` 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](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2024/04/Completed-setting-up-printer-on-Mac-using-scripts.png "Completed setting up printer on Mac using scripts") ](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2024/04/Completed-setting-up-printer-on-Mac-using-scripts.png)

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

Sample script to remove printers from Mac

\#!/bin/bash lpadmin -x <destination> echo "Printer Removed Successfully" 

   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.

[ ![Action History of a Mac after setting up printers to be removed using scripts](https:2024/04/Setting-up-printers-to-be-removed-from-Mac-using-scripts.png "Setting up printers to be removed from Mac using scripts") ](https:2024/04/Setting-up-printers-to-be-removed-from-Mac-using-scripts.png)

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](https:2024/04/Setting-up-printers-to-be-added-to-macOS-using-scripts.png "Setting up printers to be added to macOS using scripts")](https:2024/04/Setting-up-printers-to-be-added-to-macOS-using-scripts.png)

 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.