unix escape characters

I need to be able to run a unix utility that is n not in the path and has spaces in the name from an applescript.
Using something like

do shell script “/path to/the script.sh”

gives an error about an unknown token and points to the space…
I don’t know what that means and none of my guesses as to the problem have worked.

How do I do this?

Hi,

I always see them use quoted form:

set a to (choose file)
set u to quoted form of (POSIX path of a)
do shell script u

Hope it works for you.

gl,

The technical issue is that you need to double-escape the spaces in your script. The first backslash is interpreted by AppleScript to tell it to quote the next character and pass it to do shell script as-is. The trouble is that’s a space, and therefore it breaks.

To solve this you double-escape the space. The first slash tells AppleScript to escape the next character (the second slash) so that it’s passed through correctly, so;

do shell script "/path\ to/the\ script.sh"

Or, as kel suggests, quote the entire path:

do shell script (quoted form of "/path to/the script.sh")

which is always worth doing when passing filenames to ‘do shell script’.