Skip to content

Instantly share code, notes, and snippets.

@PinkShellos
Last active July 9, 2024 19:30
Show Gist options
  • Save PinkShellos/49d1fc6413ecc9b5cc6a581475e7c43b to your computer and use it in GitHub Desktop.
Save PinkShellos/49d1fc6413ecc9b5cc6a581475e7c43b to your computer and use it in GitHub Desktop.
Mac MDM Printer Deployment Script
#!/bin/zsh
# Printer installation script
displayName="" # Spaces OK
printerName=$(sed 's/ /_/g' <<< "$displayName") # NO SPACES, changes to underscores
printerModel=""
serverAddr=""
protocol="" # [ socket (HP Jetdirect) | ipp | lpd | smb ]
printerAddr="$protocol://$serverAddr/$printerName"
officeLoc=""
# opts is gathered from a computer with the printer installed using GUI and running ppdOptionsDiff.command script found in this blog post: https://www.brunerd.com/blog/2012/03/13/getting-and-setting-ppd-options-via-command-line-for-use-with-lpadmin-in-os-x/
opts=''
# PPD
PPDpath="/Library/Printers/PPDs/Contents/Resources"
PPD=""
PPDfile="$PPDpath/$PPD"
# If opts variable is null, use command without it
if [[ "$opts" == '' ]]; then
/usr/sbin/lpadmin -p "$printerName" -D "$displayName" -v "$printerAddr" -m "$printerModel" -P "$PPDfile" -L "$officeLoc" -o printer-is-shared=false -o auth-info-required=username,password -E
else
/usr/sbin/lpadmin -p "$printerName" -D "$displayName" -v "$printerAddr" -m "$printerModel" -P "$PPDfile" -L "$officeLoc" "$opts" -o printer-is-shared=false -o auth-info-required=username,password -E
fi
exit 0
@PinkShellos
Copy link
Author

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