Adding a printer from AppleScript

Hi Guys,

I’m wondering if anyone has a workable solution to automating the process of adding a printer in Leopard.

So far, it seems I can use a previously generated CUPS PPD file from another computer that was manually setup and import it into CUPS via the lpadmin(8) CLI.

I know some Terminal stuff, but so far this seems beyond me. The below is a exceprt from the man page for lpadmin(8), and it just confuses me more.

lpadmin [ -E ] [-U username ] [ -h server[:port] ] -d destination lpadmin [ -E ] [-U username ] [ -h server[:port] ] -p printer option(s) lpadmin [ -E ] [-U username ] [ -h server[:port] ] -x destination
So, I have a PPD file in an Applescript application bundle, do I cp it to /etc/cups/ppd then add it and restart cupsd?

My head hurts. Help, please!

Thanks!

Okay, so I worked something out. The only problem is that when I run it on my computer, it doesn’t ask for a password, but when i run it on any other computer, it says lpadmin needs your password, why? I’m trying to get minimal user interaction. Secondly, the computers I’m running it on have AppleTalk turned off by default, but in order to turn it on I need to open the addprinter interface, which requires access for assistive devices, something that requires user interaction.

Any ideas?

This script only works if you have it saves as an App Bundle with a PPD in it’s contents folder.

do shell script "lpadmin -p 'Genius_Bar' -D 'Genius Bar' -v 'pap://*/GB%20POS%20203/LaserWriter' -P " & the POSIX path of (path to me) & "/Contents/Resources/Genius_Bar.ppd -L 'Genius Bar' -E"
tell application "Printer Setup Utility" to set current printer to printer "Genius Bar"

tell application "AddPrinter"
	activate
	tell application "System Events"
		tell process "AddPrinter"
			activate
			delay 1
			click button 6 of tool bar of window 1
			delay 2
		end tell
	end tell
	quit
end tell

You can activate and deactivate AppleTalk with the «appletalk» command, no GUI scripting necessary.

Right. I tried appletalk -x, and appletalk -r, but neither work. I wont know what interfaces are available to the various computers, so I can’t enable en0 or en1, etc.

Also, I’m hoping to add an appletalk printer and fully get it working without prompting the user for anything, including the password.

Bleh.

Here is where I am:

do shell script "appletalk -u en0; appletalk -u en1; appletalk -u en2; lpadmin -p 'Genius_Bar' -d 'Genius_Bar' -D 'Genius Bar' -v 'pap://*/GB%20POS%20203/LaserWriter' -P " & the POSIX path of (path to me) & "/Contents/Resources/Genius_Bar.ppd -L 'Genius Bar' -E" with administrator privileges

Not exactly what I’d like, but it gets the job done.

Now I’m just trying to figure out how to write defaults settings to make it print from Tray 2. I have read com.apple.print.custompresets
but I can’t figure out how to write to the paper feed key to change it to Tray1.