Hi,
I used lpadmin in an shell script and it seems to be working fine, however there are two issues that are a major concern and i was wondering if they could be solved, I have been toiling over it for a while and seem to have hit a brick wall, any help is really appreciated. So i have the following issues
If the tpass contains “$” “&” or “#” the lpadmin command doesn’t do what it is supposed to.
The printer when added is initially “Paused” is there any way to make sure it is added without it being “Paused”.
Here is my script
try
set tuser to the text returned of (display dialog "Enter your ID:" default answer "For Example: jdoe" default button 2)
set tpass to the text returned of (display dialog "Enter your Password:" default answer "" default button 2 with hidden answer)
do shell script "lpadmin -p PrinterName -v smb://" & tuser & ":" & tpass & "@ ServerName -P /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/Resources/Generic.ppd -o printer-is-shared=false"
do shell script "accept PrinterName"
display dialog "Printer added successfully!" buttons {"Ok"} default button 1
on error
display dialog "Unable to configure Printer" buttons {"Ok"} default button 1
end try
The shell give special meaning to both ˜$’ and ˜&’ unless the are properly quoted so that they make it to the lpadmin command. ˜#’ should only be a problem if it comes directly after whitespace (where the shell takes it as the introduction of an end-of-line comment). All of these special meanings are best avoided by using quoted form of for all the user-supplied values (or really for anything that might change much) sent to a shell.
Also, it looks like an extra space snuck in after the ˜@’ in your script.
To your second question, you might try adding the ˜-E’ printer configuration option. That should cause lpadmin to do the equivalent of enable and accept. Note that the placement of the ˜-E’ is important, it must come somewhere after “-p printername”. If if comes earlier it has a different meaning to lpadmin. Alternatively you could try doing your own “enable PrinterName && accept PrinterName” instead of just accept (accept only allows jobs be queued up locally, enable actually allows queued jobs be sent to the printer). But, there is a trick to the enable command because it shares its name with a ˜built-in’ bash command that ordinarily takes precedence in shell ˜scripts’. Instead, the full “enable && accept” command should be “enable -n enable && enable PrinterName && accept PrinterName” (disable the shell builtin first) or “env enable PrinterName && accept PrinterName” (use env to avoid the shell builtin) or even “/usr/bin/enable PrinterName && accept PrinterName” (give a full path to the enable binary).
try
set tuser to the text returned of (display dialog "Enter your ID:" default answer "For Example: jdoe" default button 2)
set tpass to the text returned of (display dialog "Enter your Password:" default answer "" default button 2 with hidden answer)
set printerName to "PrinterName" -- nice to have a variable, esp if using it in multiple shell commands
set ServerName to "ServerName"
set printerURI to "smb://" & tuser & ":" & tpass & "@" & ServerName
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 "Printer added successfully!" buttons {"Ok"} default button 1
on error
display dialog "Unable to configure Printer" buttons {"Ok"} default button 1
end try
Edit History: Deleted my ˜~/cmd/pargs’ debug command prefix.