I’m trying to figure out if there is a way to script printer creation in OS X (10.3). I don’t think it can be scripting the Printer Setup Utility (all the properties are r/o), but I was thinking maybe there’s a way to edit a plist or other system file. I tried using UI scripting but that would only get me so far (I couldn’t have it selelct the printer model) and wouldn’t be very reliable. Any ideas would be greatly appreciated.
~Joe
Here’s a Perl script from macosxlabs.org that purports to add printers. I haven’t tried it, so if you get it to work, let us all know!
#!/usr/bin/perl
use File::Find; # Recurse the filesystem
use File::Copy; # Copy files
Add printers below. For multiple printers, increase array index
$ppdLab[0] = ‘_128_138_xxx_xx.ppd’; # CHANGE THIS to printer PPD
$ppdLab[1] = ‘_128_138_xxx_xx.ppd’; # Here’s a second printer, etc.
#*****************************************************
PRINTER CLEANUP
#*****************************************************
Replace the printers.conf file since the previous user may have changed something
copy (“/private/etc/cups/labprinters.conf”, “/private/etc/cups/printers.conf”);
chown(1, 80, “/private/etc/cups/printers.conf”);
for ($i = 0; $i <= (scalar @ppdLab) - 1; $i++) {
copy (“/private/etc/cups/labppds/$ppdLab[$i]”, “/private/etc/cups/ppd/$ppdLab[$i]”);
}
opendir dh, “/etc/cups/ppd”;
PPDFOLDER: foreach my $file (readdir dh) {
next if $file =~ /^./; # skip over dot files
for ($i = 0; $i <= (scalar @ppdLab) - 1; $i++) {
next PPDFOLDER if $file eq $ppdLab[$i];
}
unlink “/etc/cups/ppd/$file”; # delete everything else
}
closedir dh;
system “/usr/bin/killall -9 cupsd”;
system “/usr/sbin/cupsd”;
#*****************************************************
end PRINTER CLEANUP
#*****************************************************