Skip to content

Instantly share code, notes, and snippets.

@grahampugh
Created March 3, 2017 10:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save grahampugh/30df87d5dcfd313db8d2c92d132f857d to your computer and use it in GitHub Desktop.
Save grahampugh/30df87d5dcfd313db8d2c92d132f857d to your computer and use it in GitHub Desktop.
Printer Template Script, taking Parameter inputs from JSS.
#!/bin/bash
### -------------------------------------------------------------------------------------
### Printer Installation Template
### Graham Pugh 2015-10-05
### Adapted for JSS 2017-01-19
### -------------------------------------------------------------------------------------
### Variables. Edit these. The script will remove any existing installation of a printer
### with the same name as defined by 'printername'
printername="$5"
location="$7"
gui_display_name="$6"
server="$4"
address="smb://$4/$5"
# leave this empty if you wish to use the generic PS PPD print driver
# or choose an existing .ppd.gz file from /Library/Printers/PPDs/Contents/Resources/
# Note the best way to populate this folder is using Apple-supplied drivers (HP or Xerox)
# or with an installer pkg from your printer vendor.
driver_file="$8"
# set this to 1 if you wish to use the generic PS print driver
# or 0 if you have specified a driver_file above
generic_ppd=0
# set this to 1 if you wish this printer to be default (note the last run script will take precedence).
default_printer=0
# Populate these options if you want to set specific options for the printer. E.g. duplexing installed, etc.
option_1="auth-info-required=negotiate"
option_2="HPOption_Duplexer=True"
option_3="Duplex=DuplexNoTumble"
option_4="PageSize=A4"
### Stop editing. Don't change anything below here.
### -------------------------------------------------------------------------------------
# default printer driver for Novartis PullPrint queues
default_driver_file="HP Color LaserJet flow MFP M880.gz"
# fill in blank variables
if [[ -z "$location" ]]; then
location=$printername
fi
if [[ -z "$gui_display_name" ]]; then
gui_display_name=$printername
fi
if [[ -z "$gui_display_name" ]]; then
gui_display_name=$printername
fi
# driver locations
driver_src="/Library/Management/Printers/Drivers/${driver_file}"
if [ $generic_ppd = 1 ]; then
driver_ppd="/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/Resources/Generic.ppd"
else
if [[ -z "$driver_file" ]]; then
driver_file=$default_driver_file
fi
driver_ppd_dest="/Library/Printers/PPDs/Contents/Resources"
driver_ppd="${driver_ppd_dest}/${driver_file}"
fi
# Delete any existing instance of this printer
/usr/sbin/lpadmin -x "$printername"
# Now we can install the printer.
/usr/sbin/lpadmin \
-p "$printername" \
-L "$location" \
-D "$gui_display_name" \
-v "${address}" \
-P "$driver_ppd" \
-o "$option_1" \
-o "$option_2" \
-o "$option_3" \
-o "$option_4" \
-o printer-is-shared=false \
-o printer-error-policy=abort-job \
-E
# Make this printer default.
if [ $default_printer = 1 ]; then
/usr/sbin/lpadmin -d "$printername"
fi
# Enable and start the printers on the system (after adding the printer initially it is paused).
/usr/sbin/cupsenable $(lpstat -p | grep -w "printer" | awk '{print$2}')
@grahampugh
Copy link
Author

Set Parameter values as follows:

screen shot 2017-03-03 at 11 15 23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment