LS Ferns
LS Ferns

Reputation: 1

How to escape a special character in the output of a variable

Trying to compile an add printer command using lpadmin and running it via an Apple Script. The issue I am facing is the printer name has the special Character & and looks like this

PRINTERVALUE: DellB&W

do shell script "lpadmin -p " & PRINTERVALUE & " -E -v LPD://" & PRINTERVALUE & " -P /Library/Printers/PPDs/Contents/Resources/DellBW.ppd.gz -o printer-is-shared=false"

This gives me an error and the command halts at special character & since is part of the Printer name.. Any ideas ?

Upvotes: 0

Views: 121

Answers (2)

vadian
vadian

Reputation: 285069

Use quoted form of, it adds the necessary escape characters:

do shell script "lpadmin -p " & quoted form of PRINTERVALUE & " -E -v LPD://" & quoted form of PRINTERVALUE & " -P /Library/Printers/PPDs/Contents/Resources/DellBW.ppd.gz -o printer-is-shared=false"

Upvotes: 3

morb1d
morb1d

Reputation: 143

In general escape char is: \

Try something like this:

PRINTERVALUE: DellB\&W

or in quotes:

PRINTERVALUE: "DellB\&W"

Upvotes: -1

Related Questions