How do I escape a slash in AppleScript?

2

How do I escape a slash in AppleScript? The documentation seems to suggest that

set target_string to "\\"

should return a single \, but in fact it returns \\\\. On the other hand,

set target_string to "\"

gives an error. I've tried this on Mac OS X v10.6 (Snow Leopard) and older versions of Mac OS X.

David Zureick-Brown

Posted 2010-07-28T15:22:07.920

Reputation: 605

Sorry, not sure what's going on for you, but set target_string to "\\" returns a single \ for me on Snow Leopard (10.6.4) – ghoppe – 2010-07-28T15:48:46.897

And progress David? – peelman – 2010-07-28T17:17:33.940

Answers

2

You should just be able to do:

set target_string to "\\"

peelman

Posted 2010-07-28T15:22:07.920

Reputation: 4 580

Sorry, oddly enough SU read \ as an escape in my original question. I've edited it. For some reason, your suggestion doesn't work on for applescript on my computers. – David Zureick-Brown – 2010-07-28T15:40:40.020

2

what happens when you do something like set target_string to "\\" then do a display dialog target_string. What you see in the "return" window in Script Editor isn't necessarily what other script objects see, especially true with Strings.

like this: http://peelman.us/skitch/ase-slashes-20100728-114610.png

– peelman – 2010-07-28T15:45:08.840

1

Not sure why your sample code is not working on your system, but this should work too:

set target_string to ASCII character (92)

ghoppe

Posted 2010-07-28T15:22:07.920

Reputation: 6 124