Help with CUPS printing in Mac OS

Below is a script i’m working on however I am stuck one part which is kind of causing a lot of issues. If the user password contains “#” “%” or “@”, the script doesn’t work as it’s supposed to and the printer doesn’t send the job.

Also, is there any way to set PRINTER1 as the default printer on any mac, using this script.

Any help is really appreciated

Thanks,
mac_life



try
	set tuser to the text returned of (display dialog "Enter your ID :" default answer "For Example: jdoe" default button 2 with title )
	set tpass to the text returned of (display dialog "Enter your Password:" default answer "" default button 2 with title with hidden answer)
	
	
	set printerName to "PRINTER 1"
	set ServerName to "PRINTER1_LOCATION_HERE"
	set printerURI to "smb://" & tuser & ":" & tpass & "@" & ServerName
	
	set printerName to "PRINTER 2"
	set ServerName to "PRINTER2_LOCATION_HERE"
	set printerURI to "smb://" & tuser & ":" & tpass & "@" & ServerName
	
	
	do shell script "lpadmin -p" & quoted form of printerName2 & " -v " & quoted form of printerURI2 & " -P /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/Resources/Generic.ppd -o printer-is-shared=false -E"
	
	do shell script "lpadmin -p " & quoted form of printerName & " -v " & quoted form of printerURI & " -P /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/Resources/Generic.ppd -o printer-is-shared=false -E"
	
	
	display dialog "Added successfully!" buttons {"Ok"} default button 1
on error
	display dialog "Unable to configure" buttons {"Ok"} default button 1 
end try



Well I think the problem is, that you pass the password directly to the url query. Therefore you have to URL-encode the special characters first (http://www.blooberry.com/indexdot/html/topics/urlencoding.htm).