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.

link|improve this question

65% accept rate
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 Jul 28 '10 at 15:48
And progress David? – peelman Jul 28 '10 at 17:17
feedback

2 Answers

You should just be able to do:

set target_string to "\\"
link|improve this answer
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 Jul 28 '10 at 15:40
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: peelman.us/skitch/ase-slashes-20100728-114610.png – peelman Jul 28 '10 at 15:45
feedback

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

set target_string to ASCII character (92)
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.