Skip navigation
This discussion is archived

Escaping ampersand

2487 Views 2 Replies Latest reply: Jun 18, 2010 12:02 AM by taylor.henderson RSS
taylor.henderson Level 2 Level 2 (450 points)
Currently Being Moderated
Jun 17, 2010 10:28 PM
Hi all.

I can run the following in a shell script and escape the ampersand with a backslash

*open -a Firefox http://www.aSite.org/data.php?email=myName88%40live.com\&passwd=myPass*

In applescript the following gives me a syntax error. _Expected """ but found unknown token_

*do shell script "open -a Firefox http://www.aSite.org/data.php?email=myName88%40live.com\&passwd=myPass"*

Attempting to use "quoted form of" has also not worked. I though "\" escaped any character after it? Am I missing something here? Thanks in advance.
applebook, Mac OS X (10.5.8), the white one
  • Camelot Level 8 Level 8 (45,670 points)
    Currently Being Moderated
    Jun 17, 2010 11:59 PM (in response to taylor.henderson)
    This is a common issue.

    Both the shell and AppleScript use the backslash to escape characters - in the shell's case it tells the shell to pass the next character as-is.

    The issue you're running into is that AppleScript is jumping in and seeing the slash, which it also interprets as 'pass the next character as-is', so it strips the slash and passes the ampersand to the shell which, of course, treats it as it normally would since it is no longer escaped.

    The solution is simple, though - double-escape the ampersand. The first slash will be interpreted by AppleScript to tell it to pass the next character (the second slash) to the shell. The shell then sees a single backslash which it interprets as an escape of the ampersand. Voila!

    do shell script "open -a Firefox http://www.aSite.org/data.php?email=myName88%40live.com\\&passwd =myPass"


    (Note that if Firefox is your default web browser you can just use the simpler form:

    open location "http://www.aSite.org/data.php?email=myName88%40live.com&passwd=myPass"


    which avoids the whole escaping issue altogether.)

    Message was edited by: Camelot
    Mac OS X (10.6.3)

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.