Posted on 17th April 2015 by Amsys

Mac Printing Scripts

Hi all. I’m doing something a little different this time and I’ve got 4 small scripts relating to printers on Mac that I’d like to share. They’ve been pulled together from various places and tweaked many times since I’ve started using them and I thought I should share what I’ve got. Hopefully they’ll help save another Mac Admin some time!

Add Everyone to Printer Admins

This script uses the ‘dseditgroup’ command to add the “Everyone” user group (which all users are a member of, hence the name) to the “lpadmin” group (effectively the ‘printer admins’ group).

This change will allow all users to carry out tasks such as resuming a print queue without entering administration credentials. As long as the users are not administrative users themselves, they won’t be able to add or remove printers from the Printing System Preference pane.

I’ve used this for staff Macs in schools where the staff members would take a device home, and attempt to print to the school print server queues. Once the print job timed out, the queue would be paused and require an administrative credentials to resume.

#!/bin/sh

dseditgroup -o edit -a "everyone" -t group lpadmin

exit $?

Disable Printer Sharing On All Queues

This script uses the lpstat and lpadmin commands to disable printer sharing on all print queues. Often, when a print queue is deployed using management, it is automatically configured as shared. Now, without enabling printer sharing in the Sharing Printing System Preference pane this won’t do much, but can annoy / worry some business owners.

I’ve used this script in a handful of places where users may add print queues themselves, or the site uses a particular method to deploy print queues that typically have sharing enabled but not desired. This script can be run each time a print queue is added (afterwards!) or every day / week / month etc.

#!/bin/sh

lpstat -p | grep printer | cut -d" " -f2 | xargs -I {} lpadmin -p {} -o printer-is-shared=False

exit $?

Remove MCX Printers

This script will use the lpstat and lpadmin commands to find any print queues listed as ‘mcx’ print queues, and remove them.

I’ve used this script when migrating a few customers from one management solution to another. It pruned out the previous management solution’s print queues, ready to receive the new management solution’s queues. This ensured that the devices in question were in a ‘known’ state, rather than possibly be missing queues or have duplicate queues

#!/bin/bash

for printer in `lpstat -p | grep 'mcx ' | awk '{print $2}'` ; do
        lpadmin -x $printer
    done

exit 0

Remove All Print Queues

This script uses lpstate and lprm commands to loop through and remove all locally added printers.

I’ve used this script in a similar way to the Remove MCX Printers script above to reset a Mac device to a ‘known’ state regarding the print queues, i.e. no print queues!

#!/bin/bash

lpstat -p | awk '{print $2}' | while read printer
do
  echo "Clearing Queue for Printer:" $printer
  lprm - -P $printer
done

Summary

There you go! I hope that they can prove helpful to someone. Apologies that I cannot remember sources for the information and / or scripts. Please feel free to give me a shout out and I’ll edit the post to give credit where credit is due!

As always, if you have any questions, queries or comments, let us know below and I’ll try to respond to and delve into as many as I can.
 

 
Disclaimer:

While the author has taken care to provide our readers with accurate information, please use your discretion before acting upon information based on the blog post. Amsys will not compensate you in any way whatsoever if you ever happen to suffer a loss/inconvenience/damage because of/while making use of information in this blog.