Japanese backslash

My script runs a shell script containing a backslash (""). This causes a problem when running the script on a Japanese system (or perhaps any double-byte language), although the script is distributed in pre-compiled form (run only).

In script editor, running in Japanese, I get an “unknown token” error if I try to compile this script: “/”. If I open a script containing a backslash, the backslash is substituted with a backslash followed by some japanese token (that translates to a normal slash when pasted into a English script window, eg. “/”), but compilation still fails with an “unknown token” error.

Does anyone know of a work-around for this issue?

Hi,

the problem might be the internal text encoding of AppleScript, which is MacRoman, not Unicode text

an example:

set x to "\\" -- one Backslash!
class of x --> string which means MacRoman

So you should coerce your strings as much as possible to Unicode text

set y to "\\" as Unicode text
class of y --> Unicode text

Shell scripts work fine with arguments in Unicode text

set s to "ls /" as Unicode text
do shell script s

Thanks Stefan. Unfortunately it doesn’t solve the problem. I did some searching in the Apple mailing lists, and apparently this is a well known, long-standing bug. You simply can’t use a literal backslash on Japanese systems. I found, however, that replacing the backslash with its ASCII character number works just fine.

set backslash to ASCII character 92
return backslash & “/”

In Script Editor, this will return backslash-yen mark-slash. But at least the shell script handles it correctly.

Darn. I was wrong. ASCII number substitution fails miserably as well…

Did you try also

set backslash to (ASCII character 92) as Unicode text

or

set backslash to «data utxt005C» as Unicode text

Yep, I did now. They both result in “Ä/”…

Got it. Apparently, in MacJapanese, the backslash does not have ASCII 92 but 128 (0x80). So the proper way to do it would be:

set backslash to ASCII character 128
return backslash → “\”

Thanks Stefan for helping out.