Posted on 1st March 2017 by Darren Wallace

Advanced Printing Options

Hi All. By default, we look to deploy printer queues using scripts. This allows us to specify some default options such as A4 paper size, disabling print queue sharing, and not pausing the print queue when there’s an issue (requiring Admin details to un-pause). Additionally, this allows us to use the same method to deploy print queues for Casper or Munki.

We had one customer who needed to take this a step further. They needed to setup around 20 different default options for their queue! In this blog, I’ll cover how we figured out the options required and the final command to map the printer.

The setup…

The first bit is nice and easy:

  1. Jump on a Mac
  2. Install the printer drivers
  3. Map the printer
  4. Make sure to go into the “System Preferences” -> “Printers & Scanners” -> [your new print queue] -> and “Options & Supplies” to setup all the default settings you need for the printer
  5. Oh, and don’t forget to send some test print jobs to ensure it does work!

Discovery…

We now need to gather all the information for this queue. Firstly, find the full path to the PPD (aka driver) file used. This is typically found in “/Library/Printers/PPDs/Contents/Resources/”. Save this for later

We’re also going to need the print queue as seen by the system:

  1. Find the printer in “System Preferences” > “Printers & Scanners”
  2. Click the “Options & Supplies…” for the printer queue in question
  3. Under the line-separator is the “Device Name”. This is what we need (in the example below, this is “_10_0_0_197”)

macOS advanced printing options 1

Now we have the device name, it’s time to grab the queue settings:

  1. Fire up the Terminal application and enter the below command, substituting in the name recorded above for [PrinterName]

    lpoptions -p "[PrinterName]" -l

    For example:

    lpoptions -p "_10_0_0_197" -l

  2. Hit ‘return’ and you should see a list of options for the printer

    APOptionalDuplexer/Duplex Printing Unit: True *False
    Duplex/Duplex: *None DuplexNoTumble DuplexTumble
    PageSize/Media Size: *Letter Legal A4 ISOB5 B5 LetterSmall LegalSmall A4Small
    ManualFeed/Manual Feed: True False
    InputSlot/Media Source: *Upper

  3. The item to the left of the colon (“:”) is the name of the setting (e.g. “APOptionalDuplexer”), the items to the right are the values separated by a space (e.g. “True” “False”), and the item to the right with an asterisk (“*”) is the set option.For the above examples these would be:

    APOptionalDuplexer/Duplex Printing Unit – False
    Duplex/Duplex – None
    PageSize/Media Size – Letter
    ManualFeed/Manual Feed – [No Default set]

    InputSlot/Media Source – Upper

  4. For each required setting, grab the name of the value (if there’s two options, split with a slash (“/”) then pick the one without spaces), and grab the asterisked value. Case is important for these!!
  5. Your list should now look something like the following (these values pulled from our example):

    APOptionalDuplexer – False
    Duplex – None
    PageSize – Letter
    InputSlot – Upper

  6. We will need to take these values, and pass each of them as a command line object with the ‘-o’ flag, for example:

    -o APOptionalDuplexer=False -o Duplex=None -o PageSize=Letter -o InputSlot=Upper

The Final Command

So, how’s this all going to look? Something like this:

lpadmin -p "${name}" -v "${url}" -L "${location}" -P "${ppd}" -E -o "${option 1}" -o "${option 2}"  etc

with:

name = The GUI name for the print queue
url = The Server and printer queue address, e.g. lpd://fp-svr-01.example.com/BlackAndWhite
location = The GUI location for the print queue
ppd = The path to the PPD file used for the queue
option 1 = The first option name and key, e.g. APOptionalDuplexer=False
option 2 = The second option name and key, e.g. Duplex=None
and so on, as needed

Our example queue options would look something like the below (along with the three default options we mentioned in the introduction paragraph):

lpadmin -p "${name}" -v "${url}" -L "${location}" -P "${ppd}" -E -o printer-is-shared=false -o PageSize=A4 -o printer-error-policy="retry-current-job" -o APOptionalDuplexer=False -o Duplex=None -o PageSize=Letter -o InputSlot=Upper

(all on one line!)

Another Helpful Tip

Another little trick I found is if you use the same printer name, you can reapply the above settings (or changes to them) to the existing print queue, without adding a new one. Handy!

Wrapping it all up

So, what do you need to get things up and running?

  • Packaged copy of the required drivers for the print queue
  • Your version of the ‘one-liner’ command, with the required items added in, to map the printer (after the driver installation!)

That’s it!

Summary

And there you go, hopefully this will give you more ideas about mapping printers with some of the advanced options that more complex printers provide.

Thanks for reading through the blog, and I’ll be posting more randomness soon!

As always, if you have any questions, queries or comments, let us know below (or @daz_wallace on Mac Admins Slack) and I’ll try to respond to and delve into as many as I can.

The usual 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.