Bash Script: Fix Paused Printers In OS X

Bash Script: Fix Paused Printers In OS X

You need an administrator password to un-pause a printer in OS X.  It is possible to add a user to the lpadmin group.

sudo dseditgroup -n /Local/Default -o edit -a username lpadmin

This will give them rights to the printer, but if your users aren’t admins of their machines, this might not be something you want to open up.  This is the case for the school I work at.  My solution was to create a LaunchDaemon that would automatically detect and un-pause paused printers.

This is the Launch Daemon stored in /Library/LaunchDaemons

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>com.example.fixPausedPrinters</string>
	<key>ProgramArguments</key>
	<array>
		<string>/usr/local/triggers/fixPausedPrinters.sh</string>
	</array>
	<key>RunAtLoad</key>
	<false/>
	<key>StartInterval</key>
	<integer>1800</integer>
</dict>
</plist>

And this is the script that will run every 1800 seconds (per the StartInterval  above).

#!/bin/bash
# If no disabled printers exist
if [ -z $(lpstat -p | awk '/disabled/ {print $2}') ] &> /dev/null;then 
exit
else 
echo "DISABLED: Something is wrong with the printer(s)..."
for printer in $(lpstat -p | awk '/disabled/ {print $2}')
do
# Cancel all jobs (and their files)--disable/enable CUPS as well
cancel -ax
cupsdisable $printer
cupsenable $printer
echo -e "\tFIXED $printer"
done 
fi