Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

add printers via lpadmin (See related posts)

can be used from the cli, pushed from ARD, included in a payload-less pkg, etc. this is basically just a one-liner with comments thrown in, but no real logic. quick & dirty…

#!/bin/sh
# this script configures an hp5100 using its bonjour address as an example.
# you should run this script as root or prefix it with sudo to avoid access issues.
# also, to delete an existing printer config, use: lpadmin -x "printer name"
# to check the status of all existing queues, use lpstat -a. check lpstat's man page for more options.
#
# -p is the printer name as seen on the client
# -L is a location description, so add a real location if you want
# -E enables the printer for use immediately
# -v is the device uri. note the %20 ascii encoded spaces in the mdns uri
### for an appletalk queue, you'd want a uri like this: pap://*/PET/LaserWriter
### for a lpd queues, use something like: lpd://192.168.0.100/
# -P requires the full path to the ppd file. if there are spaces, be sure to quote the string.
# -o printer-is-shared=false means printer sharing is disabled for the newly created queue.
### 10.5 clients default to enabling sharing for reasons unknown to me.
#
lpadmin -p HP5100 -L "HP5100" -E -v mdns://HP%20LaserJet%205100%20Series%20%5BC06988%5D._printer._tcp.local. -P "/Library/Printers/PPDs/Contents/Resources/HP LaserJet 5100 Series.gz" -o printer-is-shared=false
#
# for good measure, be sure to restart cupsd.
# comment out one or the other depending on the target OS.
#
# this restarts the cupsd printing daemon under 10.4.x
/System/Library/StartupItems/PrintingServices/PrintingServices restart
#
# this restarts the cupsd printing daemon under 10.5.x
launchctl unload /System/Library/LaunchDaemons/org.cups.cupsd.plist
launchctl load /System/Library/LaunchDaemons/org.cups.cupsd.plist

You need to create an account or log in to post comments to this site.