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:
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'#!/bin/bash
#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]"
exit
fi
if [ -z "$1" -o -z "$2" ]; then
clear;
echo "Drag in the unmodified PPD from /Library/Printers/PPDs/Contents/Resources:"
while [ -z "$originalfile" ]; do
read originalfile
done
echo "Drag in the PPD from /etc/cups/ppd:"
while [ -z "$newfile" ]; do
read newfile
done
elif [ -n "$1" -o -n "$2" ]; then
newfile="$2"
originalfile="$1"
fi
#if file is compressed
if [ "${originalfile##*.}" == "gz" ]; then
#uncompress
IFS=$'\n\t'
gunzipFile="/tmp/$(basename $originalfile .gz)"
gunzip < "$originalfile" > "$gunzipFile"
originalfile="$gunzipFile"
fi
#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
IFS=$'\n\t'
if [ ! -z "$optionList" ]; then
for option in $optionList; do
echo -n "$option "
done
echo
else
echo No differences
fi
#delete the temp file from gunzipping
[ -f "$gunzipFile" ] && rm "$gunzipFile"
exit
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
Mac OS X Hints
http://hints.macworld.com/article.php?story=20120313110411984