'How do I enable duplexer of a printer with macOS terminal?

I am writing a script to automatically setup the printer for macOS, and need to set the printer-type param in order to enable the duplexer. I failed with the command: lpoptions -d my_printer_name -o printer-type=xxx.

Details:

  1. I added the printer successfully with lpadmin, but it can not make a two-sided print.
  2. Then I found that I should go to System Preferences - Printers & Sacnners - Options & Supplies and enable Duplexer under Options tab, as shown in this picture. Enable Duplexer.
  3. Then I checked the lpoptions settings for my printer and found that the difference between enabled and disabled duplexer is the printer-type parameter:
    • For enabled duplexer, printer-type=2109508 while for disabled duplexer, printer-type=2109524.
  4. Therefore, I was thinking to set the printer-type param by lpoptions -d my_printer_name -o printer-type=2109524, but the printer-type did not change as expected.

The script is shown below, it can add the printer but can not enable the duplexer.

printer_driver="drv:///sample.drv/generpcl.ppd"

black_white_printer_name="BlackWhitePrinter"
black_white_printer_device="socket://xxxxxx/"
lpadmin -p $black_white_printer_name -E -v $black_white_printer_device  -m $printer_driver -o printer-is-shared=false
# set default printer
# -o printer-type=2109524 does not work
lpoptions -d $black_white_printer_name -o printer-type=2109524



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source