Chapter 4. Manipulating Text
Since the ancient days of DOS, text has always played an important role in computing. Even today, 20 years after the first Mac came out, every computer Apple ships comes with a keyboard. What’s more, Mac OS X’s Unix core is strictly based on text: preference files are in plain text, and the commands you issue in Terminal (Section 13.1) are all, well, text.
The importance of text isn’t lost on AppleScript, though. From its dialog box capabilities to the Text Suite—a standard set of AppleScript keywords that deals with the details of words, characters, and paragraphs (Section 4.6.1)—AppleScript handles text the way Mac OS X does: simply and powerfully. For example, you can harness AppleScript’s text mojo to do things like:
Add a word count feature to TextEdit (Section 4.6)
Shrink all the fonts in a document simultaneously (Section 4.7.2)
Type and run AppleScript commands in just about any program—not just Script Editor—using an application’s Services menu
AppleScript’s text features are quite powerful, but they’re not always easy to learn—especially if you’re reading Apple’s geeky help files. Thankfully, you don’t have to; just continue reading this chapter instead.
Note
The example scripts from this chapter can be found on the AppleScript Examples CD (see Sidebar 2.1 for instructions).
String Notation
In AppleScript, pieces of text are stored in a format called strings. A string can contain as many letters, numbers, spaces, and punctuation marks as you’d like. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access