Basics of AppleScript

Escape Sequences

What if I want to add double quotes inside the string declaration. Escape Sequences allow us to add new line, double quotes, etc in the string itself. It is always declared using a .

Script [5.5.1]:

set exampleString to "Nayan is \"Awesome\""
display dialog exampleString

Explanation: In output we will have Nayan is "Awesome"

Figure 5.5.1

Figure 5.5.1 Escape Sequence Output

Script [5.5.2]:

set exampleString2 to "Nayan is     Awesome"
display dialog exampleString2

Explanation: In output we will have Nayan is Awesome. There will be tab space between is and Awesome as \t signifies tab space.

Figure 5.5.2

Figure 5.5.2 Adding Tab Space

Another thing to note is that if you add an escape sequence and then compile the program, the escape sequence will get converted to what it actually means.

e.g. \t will get converted to (tab space)

Figure 5.5.2-2

Figure 5.5.2-2 Compiled Program with Escape Sequence

Other Escape Sequences include \n for new line, \? for question mar, \’ for single quotes, etc.

Script [5.5.3]: display dialog "Nayan \\\" Seth"

Explanation: In output we will have a dialog. The dialog will print Nayan \" Seth. \ gets converted to \ and \" gets converted to "

Figure 5.5.3

Figure 5.5.3 Printing \ and "