Become a MacRumors Supporter for $25/year with no ads, private forums, and more!

AvilaMac

macrumors newbie
Original poster
Feb 19, 2012
1
0
Hi All,

I am a school technician with over 600 macs onsite. There are several printers that the users here use. I have figured out the script for installing a printer using applescript but what I would really like to do is include the driver in the app so that users do not have to look for the drivers. Any idea how I can include the driver in my applescript? Right now the printer installation will only work if the driver is already installed on the machine.

do shell script "lpadmin -p PRINTERNAME -L 'Printer Location' -E -v ipp://'Printer address' /Library/Printers/PPDs/Contents/Resources/HP\\ Laserjet\\ 4250.gz -D \"Printer Queue Name\""​

How do I use Bundle Content to add the driver to script? Please advise
 

kryten2

macrumors 65816
Mar 17, 2012
1,044
76
Belgium
Place the "HP Laserjet 4250.gz" file in the Resources folder of your application bundle. Then try this :

Code:
set thePrinterDriver to (path to me) & "Contents:Resources:HP Laserjet 4250.gz"
do shell script "lpadmin -p PRINTERNAME -L 'Printer Location' -E -v ipp://'Printer address'" & space & thePrinterDriver & space & "-D \"Printer Queue Name\""

or

Code:
set thePrinterDriver to ((path to me) & "Contents:Resources:HP Laserjet 4250.gz" as string)

My gut feeling says the above code is not going to work so I think it would be better to copy the included "HP Laserjet 4250.gz" file in the Resources folder of your application bundle to the appropriate location. In your case /Library/Printers/PPDs/Contents/Resources/


Code:
set thePrinterDriver to ((path to me) & "Contents:Resources:HP Laserjet 4250.gz" as string)
set thePrinterFolderPath to ((path to "impr" from local domain) & "PPDs:Contents:Resources:" as string)
tell application "Finder"
	-- Copy file from application bundle if it doesn't exixt
	if not (exists thePrinterFolderPath & "HP Laserjet 4250.gz") then
		try
			duplicate thePrinterDriver to thePrinterFolderPath
		on error theErr number theErrNmbr
			display dialog "Finder encountered an error while trying to copy a file." & return & theErr & theErrNmbr
		end try
	end if
end tell
do shell script "lpadmin -p PRINTERNAME -L 'Printer Location' -E -v ipp://'Printer address' /Library/Printers/PPDs/Contents/Resources/HP\\ Laserjet\\ 4250.gz -D \"Printer Queue Name\""

Script is tested with admin account. Don't know if you need admin privileges to copy to the /Library/Printers/PPDs/Contents/Resources/ folder. The Finder didn't ask for credentials when I manually copied a driver file.
Note : There's a /Library/Printers/PPDs/Contents/Resources/ and a /System/Library/Printers/PPDs/Contents/Resources/ folder. Like I said this one copies to the /Library/Printers/PPDs/Contents/Resources/. If you need to copy to the other modify the script accordingly.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.