在AppleScript字符串中使用引号

haw*_*con 14 applescript

我正在使用AppleScript,需要这样做:

set TextToWrite to " #!/bin/bash cd "$( dirname "$0" )" java -server -Xmx4G -jar ./craftbukkit.jar" "
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我需要在字符串中生成的文本中包含引号.我该怎么设置

#!/bin/bash cd "$( dirname "$0" )" java -server -Xmx4G -jar ./craftbukkit.jar"
Run Code Online (Sandbox Code Playgroud)

没有引号乱搞的AppleScript字符串?

kop*_*hke 17

要将文字引号插入Applescript字符串,您必须转义它们,即

set myString to "This is a \"quoted\" text."
Run Code Online (Sandbox Code Playgroud)

AppleScript与大多数语言具有相同的约定,即使用反斜杠转义特殊字符,其中只有两个:引号和...反斜杠.请参阅AppleScript语言指南的"特殊字符串字符"部分.

  • 另请注意,如果将这些引号传递给shell,那么在AppleScript字符串中使用引号会有很多问题,其中大多数都与shell处理转义和未转义引号的方式有关.有关更多详细信息,请参阅[此问题](http://stackoverflow.com/questions/8138167/how-can-i-escape-shell-arguments-in-applescript). (3认同)