Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using quotes in a AppleScript string

Tags:

applescript

I am working with AppleScript and need to do this:

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

As you can see, the text I need to make into a string has quotes in it. How do I set

#!/bin/bash cd "$( dirname "$0" )" java -server -Xmx4G -jar ./craftbukkit.jar"

to an AppleScript string without the quotes messing it up?

like image 233
hawkfalcon Avatar asked May 19 '12 18:05

hawkfalcon


2 Answers

To insert literal quotes into an Applescript string, you have to escape them, i.e.

set myString to "This is a \"quoted\" text."

AppleScript has the same convention as most languages, which is to use a backslash for escaping of special characters, of which there are only two: quotes and … backslash. See the section “Special string characters” of the AppleScript Language Guide.

like image 134
kopischke Avatar answered Nov 09 '22 13:11

kopischke


The following syntax can also be used:

set aString to "quoted"
set myString2 to "This is a " & quoted form of aString & " text."
like image 33
John Sidiropoulos Avatar answered Nov 09 '22 13:11

John Sidiropoulos