Skip to main content

We have four networked printers that are pushed out to all Macs through our company that are tied to different locations where offices are located across the world.  We noticed that these printers have recently started installing duplicates on users' Macs and I cannot figure out why.  I have tried to write some scripts to delete duplicate printers on a few test Macs but no luck.  This has been working great for about a year and just recently started installed duplicate printers. I have also tested to push multiple printers to my own Mac but it never duplicates after the printer policy runs. Scratching my head on this.

 

This is what I have setup in Jamf.

 

1. Printer Policy 

Trigger: Login

Execution Frequency: Once per month

Packages: Canon PS Installer pkg

Printer: XXX Printer Action: Map (I also have the ppd printer setup in Jamf Settings)

Maintenance: Update Inventory

 

Here is the script I am using to try and delete the duplicate printers:

#!/bin/bash # Check if lpstat is available if ! command -v lpstat &> /dev/null; then echo "lpstat could not be found. Please ensure CUPS is installed and running." exit 1 fi # Get a list of all installed printers printers=$(lpstat -p | awk '{print $2}') # Check if there are any printers installed if [ -z "$printers" ]; then echo "No printers found." exit 0 fi # Create an array to track printer base names declare -a printer_basenames # Function to check if an element exists in an array element_in_array() { local element="$1" shift for e; do [[ "$e" == "$element" ]] && return 0; done return 1 } # Loop through the list of printers for printer in $printers; do # Extract the base name of the printer (without numbers or trailing spaces) base_name=$(echo "$printer" | sed 's/[0-9]*$//') # Check if the base name is already in the array if element_in_array "$base_name" "${printer_basenames[@]}"; then # If it is, this is a duplicate, so delete it echo "Removing duplicate printer: $printer" lpadmin -x "$printer" else # If it's not, add it to the array printer_basenames+=("$base_name") fi done echo "Duplicate printers removed."

 

I got it figured out.  CUPS network name was by IP and the printers I setup last year, the CUPS name were the actual name of the printers in each office.  Wrote a script to remove the printers I did not want by CUPs name.  Issue resolved.