Let’s say you want to encourage your users to print in black and white, to save costs, but not annoy them too much.
Assuming you are running Jamf or any other MDM solution capable of running a script once a week, and if you can create two separate print queues, one for color and another for grayscale, this is doable.
This script makes the following assumptions:
- You’ve deployed a .pkg with relevant printer drivers.
- You’ve deployed a configuration profile pre-approving any kernel extensions those drivers might need.
- You’ve set up two local print queues, one for color and another for grayscale, configured these in the CUPS web interface, creating a package deploying the resulting PPDs to /usr/local/ppd. Doing a diff between the two PPDs should reveal the color setting.
- Deploying a configuration profile to make sure the org.cups.PrintingPrefs UseLastPrinter -bool “FALSE” setting also set with the defaults write command in the script sticks.
The script will revert to the grayscale queue once a week, if the color queue is selected. If a different printer, for instance a home printer, is selected, the script does nothing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # macOS printer script: if color queue is selected, revert to grayscale | |
| # Get logged in user | |
| loggedInUser=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");') | |
| # If the print queues have been deleted, re-add them | |
| if lpstat -a | grep -q -w "Color_Printer" | |
| then | |
| echo "Color_Printer exists"; | |
| else | |
| /usr/sbin/lpadmin -p "Color_Printer" -v "smb://printserver/follow_you" -P "/usr/local/ppd/colour_printer.ppd" -o printer-is-shared=false -o auth-info-required=username,password -o printer-is-accepting-jobs=true -o printer-location='Follow You'; | |
| /usr/sbin/cupsenable "Color_Printer"; | |
| /usr/sbin/cupsaccept "Color_Printer"; | |
| fi | |
| if lpstat -a | grep -q -w "Grayscale_Printer" | |
| then | |
| echo "Grayscale_Printer exists"; | |
| else | |
| /usr/sbin/lpadmin -p "Grayscale_Printer" -v "smb://printserver/follow_you" -P "/usr/local/ppd/grayscale.ppd" -o printer-is-shared=false -o auth-info-required=username,password -o printer-is-accepting-jobs=true -o printer-location='Follow You'; | |
| /usr/sbin/cupsenable "Grayscale_Printer"; | |
| /usr/sbin/cupsaccept "Grayscale_Printer"; | |
| fi | |
| # Makes black and white default if Color_Printer is currently chosen, does nothing if any other printer is selected | |
| if sudo -u "$loggedInUser" lpstat -d | grep -q -w "Color_Printer" | |
| then | |
| echo "Color_Printer is standard, reverting to Grayscale_Printer"; | |
| defaults write /Library/Preferences/org.cups.PrintingPrefs UseLastPrinter -bool "FALSE"; | |
| sudo -u "$loggedInUser" /usr/bin/lpoptions -d "Grayscale_Printer"; | |
| /usr/bin/lpoptions -d "Grayscale_Printer"; | |
| else | |
| echo "Color_Printer is not default, not changing to Grayscale_Printer"; | |
| fi | |
| exit 0 |