Printers not showing in System Preferences UI, despite being present with lpstat command (El Capitan)

benshawuk
New Contributor III

Has anyone else come across this?
Since upgrading machines to El Capitan, around 1 in 5 macs exhibit this problem.
Doing lpstat -p from the terminal lists the installed printers, suggesting that they are present. However, no printers show in the System Preferences UI (or the print dialog from applications).

Resetting the printing system resolves this, but I can't think of a way to programmatically check this via a script, as lpstat doesn't appear to be aware of the problem..
Any advice appreciated, thanks.

1 ACCEPTED SOLUTION

jkuo
Contributor

Yes, I've seen this on various versions of OS X. To get around it, you'll need to remove the printers using lpadmin and then re-add them. In fact, I have a Self-Service package that installs the drivers and then runs a script that cancels all pending jobs in print queues, removes all the printers and re-adds them using lpadmin. That way, whenever a user runs into a printer issue, I just say "Go to Self-Service and click the Install button next to add printers."

My script looks something like this:

#!/bin/sh

# Clear out all queues on startup

cancel -a -

# Delete all vestiges of old Printers

lpadmin -x PrinterName1
lpadmin -x PrinterName2
lpadmin -x PrinterName3

# Tests to see if printer exists
# Requires the printer name as a parameter.  Returns 1 if the printer exists.
function printerExists()
{
  if [ $# -ne 1 ]; then
    echo "Incorrect parameters"
    return 0
  else
    lpstat -p | awk '{print $2}' | while read printer
    do
      if [ $1 = "${printer}" ]; then
        return 1
      fi
    done
  fi    
}

# Function to add printer, requires 6 variables, prName, prDescription, prLocation, prAddress, prPPD, and prOptions
function addPrinter()
{
    if [ $# -ne 6 ]; then
        echo "Incorrect parameters"
        return 0
    else
        printerExists $1
        prExists=$?
        prName=$1
        prDescription=$2
        prLocation=$3
        prAddress=$4
        prPPD=$5
        prOptions=$6

        if [ $prExists -eq 1 ]; then
            echo "Printer already exists. Skipping: "$prName""
        else
            #Execute add printer command
            echo "Adding: "$prName""
            /usr/sbin/lpadmin -p "${prName}" -E -v lpd://"${prAddress}"/ -P "/Library/Printers/PPDs/Contents/Resources/$prPPD" -D "${prDescription}" "${prOptions}" -L "${prLocation}"
        fi
    fi
}

# Printer Name 1, on the north side next to the water cooler
prName="PrinterName1"
prDescription="Printer Name 1"
prLocation="North Side next to the water cooler"
prAddress="x.x.x.x"
prPPD="blahblahblah.ppd.gz" # actual name of the ppd
prOptions="-o printer-is-shared=false -o PageSize=Letter"

addPrinter "${prName}" "${prDescription}" "${prLocation}" "${prAddress}" "${prPPD}" "${prOptions}"

View solution in original post

3 REPLIES 3

jkuo
Contributor

Yes, I've seen this on various versions of OS X. To get around it, you'll need to remove the printers using lpadmin and then re-add them. In fact, I have a Self-Service package that installs the drivers and then runs a script that cancels all pending jobs in print queues, removes all the printers and re-adds them using lpadmin. That way, whenever a user runs into a printer issue, I just say "Go to Self-Service and click the Install button next to add printers."

My script looks something like this:

#!/bin/sh

# Clear out all queues on startup

cancel -a -

# Delete all vestiges of old Printers

lpadmin -x PrinterName1
lpadmin -x PrinterName2
lpadmin -x PrinterName3

# Tests to see if printer exists
# Requires the printer name as a parameter.  Returns 1 if the printer exists.
function printerExists()
{
  if [ $# -ne 1 ]; then
    echo "Incorrect parameters"
    return 0
  else
    lpstat -p | awk '{print $2}' | while read printer
    do
      if [ $1 = "${printer}" ]; then
        return 1
      fi
    done
  fi    
}

# Function to add printer, requires 6 variables, prName, prDescription, prLocation, prAddress, prPPD, and prOptions
function addPrinter()
{
    if [ $# -ne 6 ]; then
        echo "Incorrect parameters"
        return 0
    else
        printerExists $1
        prExists=$?
        prName=$1
        prDescription=$2
        prLocation=$3
        prAddress=$4
        prPPD=$5
        prOptions=$6

        if [ $prExists -eq 1 ]; then
            echo "Printer already exists. Skipping: "$prName""
        else
            #Execute add printer command
            echo "Adding: "$prName""
            /usr/sbin/lpadmin -p "${prName}" -E -v lpd://"${prAddress}"/ -P "/Library/Printers/PPDs/Contents/Resources/$prPPD" -D "${prDescription}" "${prOptions}" -L "${prLocation}"
        fi
    fi
}

# Printer Name 1, on the north side next to the water cooler
prName="PrinterName1"
prDescription="Printer Name 1"
prLocation="North Side next to the water cooler"
prAddress="x.x.x.x"
prPPD="blahblahblah.ppd.gz" # actual name of the ppd
prOptions="-o printer-is-shared=false -o PageSize=Letter"

addPrinter "${prName}" "${prDescription}" "${prLocation}" "${prAddress}" "${prPPD}" "${prOptions}"

benshawuk
New Contributor III

@jkuo Many thanks for that. I guess the safest option is to reset the printing system and reinstall all printers, regardless of whether the problem is there (as it seems to be undetectable via scripting as far as I can see).

I've done a fair bit of printer scripting, but not come across the "cancel" command before either, thanks.

jkuo
Contributor

You're welcome! Yeah, I haven't found a way to determine whether the printers are "really" there or not, so I just use the "clean it all out and re-add them" way. :)