Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Getting and setting printer options from the command line for use with lpadmin UNIX
lpadmin and lpoptions don't interact with OS X as you might think, or at least as they are documented. Here are some helpful notes and a script.
There are some good hints for adding printers via the command line with lpadmin: Managing multiple printers via the command line.
However, there is still confusion surrounding the setting of printer options from the command line, as a poster to Debian bugs pointed out back in 2006: lpoptions documentation doesn't. After doing some testing, here are the two main points to note:

  • If you use lpadmin and specify options with "-o", the PPD is altered and OS X will recognize the options for the printer.
  • However, if you setup the printer using lpadmin without any options, and later use lptoptions to set the options, they are not written to the PPD and the GUI is unaware of the printer's options.

    More helpful hints about lpadmin and lpoptions:
    lpoptions -p printername -l
  • Prints PPD options, "Default" is filtered from option name (similar to looking at the raw PPD)
  • It uses a colon when reporting key value pairs; replace that with an equals sign when specifying an option
  • The option name stops at the first slash
  • Example: The duplex option for HP printers will output like this "HPOption_Duplexer/Duplex Unit: *True False"
    When specified as a "-o" option it would be "HPOption_Duplexer=True"

  • lpadmin ... -o this=that
  • Alters the ppd that is placed in /etc/cups/ppd/ when the printer is installed

    Unhelpful things:
    lpoptions -p printername
  • These are NOT the PPD options you want to set

    lpoptions -o
  • This only writes options to: /private/etc/cups/lpoptions (run with sudo) or ~/.cups/lpoptions (run as current user), GUI apps are unaware of these options

  • The following script compares the original and the newly installed PPD to generate the options syntax to be used with lpadmin

    The main magic in this script is a little diff and sed:
    diff "$originalfile" "$newfile" | grep "> [*]Default" | sed 's/> [*]Default/-o /g' | sed 's/: /=/g'

    Script Workflow
  • Copy and paste the script into TextWrangler, save with a .command extension and it will automatically take care of the executable bit.
  • Setup your printer via the Printers Preference Pane in the GUI.
  • Look in /etc/cups/ppd and find the newest .ppd (it will have the same name as the printer).
  • Locate the original .ppd.gz (or .ppd) in /Library/Printers/PPDs/Contents/Resources/. The printer's ppd is usually easy to find by name, but some printers, such as those from Canon, have some cryptic filenames. Look inside the /etc/cup/ppd file; the "PCFileName" variable sometimes helps to determine the file name.
  • Run the script given below; it will ask you to drag in the original and the modified ppds. Out will come the "-o" options for use with lpadmin.
  • You can also run the script with the original and modified file paths as arguments and the string will be output.

    The script "ppdOptionsDiff.command":
    #set -x
    #ppd option maker
    if [ "$1" == "-h" ]; then
    echo "$(basename $0) compares two ppds and outputs the differences as a string for use in lpadmin"
    echo "Usage: $(basename $0) [original_ppd] [new_ppd]"
    if [ -z "$1" -o -z "$2" ]; then
    echo "Drag in the unmodified PPD from /Library/Printers/PPDs/Contents/Resources:"
    while [ -z "$originalfile" ]; do
    read originalfile
    echo "Drag in the PPD from /etc/cups/ppd:"
    while [ -z "$newfile" ]; do
    read newfile
    elif [ -n "$1" -o -n "$2" ]; then
    #if file is compressed
    if [ "${originalfile##*.}" == "gz" ]; then
    gunzipFile="/tmp/$(basename $originalfile .gz)"
    gunzip < "$originalfile" > "$gunzipFile"
    #test for file existence
    if [ ! -f "$originalfile" ]; then echo "$originalfile is not a valid path"; exit; fi 
    if [ ! -f "$newfile" ]; then echo "$newfile is not a valid path"; exit; fi 
    #create options list by diffing and filtering
    optionList=$(diff "$originalfile" "$newfile" | grep "> [*]Default" | sed 's/> [*]Default/-o /g' | sed 's/: /=/g')
    #print out the options with no line breaks
    if [ ! -z "$optionList" ]; then
    for option in $optionList; do 
    	echo -n "$option "
    echo No differences
    #delete the temp file from gunzipping
    [ -f "$gunzipFile" ] && rm "$gunzipFile"
    Example with pathnames provided as arguments (otherwise runs in interactive mode):
    $ ./ppdOptionsDiff.command /Library/Printers/PPDs/Contents/Resources/HP\ LaserJet\ 5200.gz /private/etc/cups/ppd/PRINTERNAME.ppd 
    -o HPOption_Tray3=Tray3_500 -o HPCollateSupported=True -o HPOption_Duplexer=True -o HPOption_Disk=RAMDisk
    Use the string generated in lpadmin to set the printer options.

    [kirkmc adds: A very extensive presentation; thanks. I haven't tested or investigated any of this.]
  •     •    
    • Currently 4.00 / 5
      You rated: 5 / 5 (7 votes cast)

    Getting and setting printer options from the command line for use with lpadmin | 7 comments | Create New Account
    Click here to return to the 'Getting and setting printer options from the command line for use with lpadmin' hint
    The following comments are owned by whoever posted them. This site is not responsible for what they say.
    Authored by: joelbruner on Mar 16, '12 08:54:09AM

    D'oh the script got mangled... A corrected version will be coming soon...

    Edited on Mar 16, '12 08:54:33AM by joelbruner

    [ Reply to This | # ]
    Authored by: kirkmc on Mar 16, '12 09:57:00AM

    I've just posted a new version of the code... Please check that it's ok.

    Mac OS X Hints editor - Macworld senior contributor

    [ Reply to This | # ]
    Getting and setting printer options from the command line for use with lpadmin
    Authored by: baltwo on Mar 17, '12 06:44:19PM

    Have you tried via CUPS?

    [ Reply to This | # ]
    Getting and setting printer options from the command line for use with lpadmin
    Authored by: joelbruner on Mar 19, '12 01:46:11PM

    Yes, thanks. You can set printer options via the CUPS web interface just as you would in the Printers Preference pane. However, the point of this hint is for obtaining these values in a form that can be used with lpadmin for mass deployment via the command line.

    [ Reply to This | # ]
    Getting and setting printer options from the command line for use with lpadmin
    Authored by: carlnunes on Mar 20, '12 07:27:53AM
    Download the latest version of Install OS X Option-click the Purchases tab in the App Store and you will be able to "Install" (download) the latest version available
    In my experience; this caused my account to be charged about 30 dollars; even though I was downloading it to my new Macbook Pro 2011 with Lion. The Apple Store graciously gave me my "one free accidental purchase" and credited my account.

    [ Reply to This | # ]
    Wrong Hint
    Authored by: joelbruner on Mar 26, '12 09:13:24AM
    I believe you meant to leave this comment on my other hint for Lion RecoveryHD Updater
    However to address it: Option Clicking on Purchases and re-downloading is the recommended way from Apple:
    To redownload the installer on a computer running OS X Lion, press and hold the Option key while you click the Purchases tab. If the button to the right of the Install Mac OS X Lion item doesn't change to "Install" and allow you to download Lion, use Spotlight to search for "Install Mac OS X Lion" on your computer.
    So it should not result in an additional charge, that is why it shows up in "Purchases" - meaning you have already purchased, thus they can't double bill you. So this must have been an error or glitch and they rightly refunded your money. But in general people should not fear being double billed for downloading Lion again in the way described.

    [ Reply to This | # ]
    Watch out for newline characters
    Authored by: joelbruner on Feb 11, '13 10:37:44AM

    I found some vendors use different line endings, some CR/LF, some LF, other CR
    This script gets hung up on the those, so you might need to open the ppds in TextWrangler and normalize the line endings to Unix for the script to work.

    [ Reply to This | # ]