Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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

You should just be able to do:

set target_string to "\\"
share|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
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 Jul 28 '10 at 15:45

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .