5.1. Strings, Text, and Unicode Text

Recall that a character string is simply one or more characters contained within a pair of double quotes. The quotes define the beginning and end of the string, but they do not actually get stored as part of the string. So when you write a statement like this:

set message to "Good afternoon!"

just the 15 characters between the quotes get stored inside message, and not the quotes themselves.

You can make your strings as long as you like. When entering long character strings, you can let Script Editor wrap the string to the next line for you. If you break the string by entering the line continuation character Option-L (or Option-Return in Script Editor) or by simply pressing the Return key, that character becomes part of the string, which may not be your intention.

You can have different types of strings in AppleScript, and they are summarized in the following list:

  • string: A sequence of zero or more characters.

  • text: For all intents and purposes, the same as string, even though it exists as a distinct class from string. You can coerce a value to string or to text; it makes no difference, the result is a string.

  • styled text: Refers to a string that may contain font and style information. For example, it might be a string of text that is in 10 point Times Roman. The style information is stored as part of the text. This type is not used much in AppleScript programs.

  • nicode text: A string that can represent characters from international character sets. ...

Get Beginning AppleScript® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.