Note: This project was archived by author Nick McSpadden on 8/11/20.
I plan to make additional commits in this fork and continue using it. Pull requests are welcome.
- wycomco has another fork that is under active development and is worth checking out.
PrinterGenerator
This script will generate a "nopkg" style pkginfo file for Munki to install a printer.
See Managing Printers with Munki for more details.
Usage
The script can either take arguments on the command line, or a CSV file containing a list of printers with all the necessary information.
The script will generate a pkginfo file. This pkginfo file is a "nopkg" style, and thus has three separate scripts:
- installcheck_script
- postinstall_script
- uninstall_script
The installcheck_script looks for an existing print queue named PRINTERNAME. If it does not find one, it will exit 0 and trigger an installation request. If it does find one, it will compare all of the options provided (DRIVER, ADDRESS, DISPLAYNAME, LOCATION, and OPTIONS) for differences. If there are any differences, it will trigger an installation request.
The postinstall_script will attempt to delete the existing print queue named PRINTERNAME first, and then will reinstall the queue with the specified options.
Note that it does not check to see if the printer queue is in use at the time, so it is possible that existing print jobs will be cancelled if a user is printing when a Munki reinstall occurs.
The uninstall_script will delete the printer queue named PRINTERNAME if uninstallation is triggered.
Using a CSV file:
A template CSV file is provided to make it easy to generate multiple pkginfos in one run. Pass the path to the csv file with --csv:
./print_generator.py --csv /path/to/printers.csv
Note: if a CSV file is provided, all other command line arguments are ignored.
The CSV file's columns should be pretty self-explanatory:
- Printer name: Name of the print queue
- Location: The "location" of the printer
- Display name: The visual name that shows up in the Printers & Scanners pane of the System Preferences, and in the print dialogue boxes. Also used in the Munki pkginfo.
- Address: The IP or DNS address of the printer. The template uses the form:
lpr://ADDRESS. Change to another protocol in the template if necessary. - Driver: Name of the driver file in /Library/Printers/PPDs/Contents/Resources/.
- Description: Used only in the Munki pkginfo.
- Options: Any printer options that should be specified. These must be space-delimited key=value pairs, such as "HPOptionDuplexer=True OutputMode=normal". Do not use commas to separate the options, because this is a comma-separated values file.
- Version: Used only in the Munki pkginfo.
- Requires: Required packages for Munki pkginfo. These must be space-delimited, such as "CanonDriver1 CanonDriver2".
- Icon: Optionally specify an existing icon in the Munki repo to display for the printer in Managed Software Center.
The CSV file is not sanity-checked for invalid entries or blank fields, so double check your file and test your pkginfos thoroughly.
Command-line options:
A full description of usage is available with:
./print_generator.py -h
usage: print_generator.py [-h] [--printername PRINTERNAME] [--driver DRIVER]
[--address ADDRESS] [--location LOCATION]
[--displayname DISPLAYNAME] [--desc DESC]
[--requires REQUIRES]
[--options [OPTIONS [OPTIONS ...]]]
[--version VERSION] [--icon ICON] [--csv CSV]
Generate a Munki nopkg-style pkginfo for printer installation.
optional arguments:
-h, --help show this help message and exit
--printername PRINTERNAME
Name of printer queue. May not contain spaces, tabs, #
or /. Required.
--driver DRIVER Name of driver file in
/Library/Printers/PPDs/Contents/Resources/. Can be
relative or full path. Required.
--address ADDRESS IP or DNS address of printer. If no protocol is
specified, defaults to lpd://. Required.
--location LOCATION Location name for printer. Optional. Defaults to
printername.
--displayname DISPLAYNAME
Display name for printer (and Munki pkginfo).
Optional. Defaults to printername.
--desc DESC Description for Munki pkginfo only. Optional.
--requires REQUIRES Required packages in form of space-delimited
'CanonDriver1 CanonDriver2'. Optional.
--options [OPTIONS [OPTIONS ...]]
Printer options in form of space-delimited
'Option1=Key Option2=Key Option3=Key', etc. Optional.
--version VERSION Version number of Munki pkginfo. Optional. Defaults to
1.0.
--icon ICON Name of exisiting icon in Munki repo. Optional.
--csv CSV Path to CSV file containing printer info. If CSV is
provided, all other options are ignored.