Printer setup and delete

I’m using a small script to setup printers automagically in a lab environment. Here’s the process…

  • At startup, force distribute files /etc/cups/printers.conf & printers.conf.0 as well as required ppd files in /etc/cups/ppd/

  • At login, logout & startup, run this script:

do shell script “rm /Users/MacAdministrator/.lpoptions”
end try
do shell script “/System/Library/StartupItems/PrintingServices/PrintingServices restart”
end try

OK, this works fine, except I want to add to the AppleScript the deletion of existing printers. So I add these lines at the beginning:

do shell script “lpadmin -x all”
end try

But, alas it does nothing, and in testing the command in the terminal I find that the “-x all” does not work. What happened to the “-x all” modifier for lpadmin in OS X? Is there some other way I can delete all current printers in a single line? Any other ideas?

Hmm… perhaps some small shell script?

do shell script "for i in `lpstat -p | awk '{print $2'}`; do lpadmin -x $i; done"

lpstat -p | awk ‘{print $2’}` provides a list of all printers, you may test it on the shell manually. The rest is simple bash scripting…

(haven’t tested it, this is your thing to do - and your risk :wink: )


Model: iBook (g3/800, 14,1")
AppleScript: 1.9.3
Browser: Safari 312
Operating System: Mac OS X (10.3.9)