Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL

Recipe 12. Add AppleScript Support > Step 4: Add the Text Suite and a Document ... - Pg. 542

Step 4: Add the Text Suite and a Document Text Property The diary document contains nothing but rich text. It is not a database. Although it is organized conceptually into separate diary entries having a defined structure, it has no inherent structure. It's just a stream of rich text. This has two consequences for purposes of AppleScript support. First, a scripter will find it very useful to be able to manipulate the text using the well-defined and estab- lished text-handling features of the AppleScript Text Suite, which supports reading and writing text broken into characters, words, sentences, and paragraphs. Second, a scripter will want to manipulate the several conceptually separate diary entries as if they were records in an array. AppleScript and Cocoa Scripting are adept at achieving both goals. Cocoa Scripting is designed so that you can easily manipulate any data as if it were an array of ordered items or a set of unordered items, even if the data is not organized in that way. In this step, you implement the first goal, adding the ability to script the diary docu- ment as text. In Step 5, you will create a new Objective-C class, DiaryEntry, strictly for the purpose of allowing AppleScript to treat the diary document as an ordered array of separate diary entry records having defined fields. The DiaryEntry class will support the new diary entry class in the sdef file. 1. The Text Suite is another terminology suite provided by Apple, like the Standard Suite. Currently, the Text Suite differs from the Standard Suite in that a defini- tive version is not in the /System/Library/ScriptingDefinitions folder where it could be included in application dictionaries using the XInclude mechanism. Instead, you must find it somewhere else and paste it into your sdef file. The first promising source you might stumble upon is the Sketch.sdef file in the Sketch example project in your Developer folder at /Developer/Examples/Sketch. However, Apple has unofficially acknowledged that this version of the Sketch. sdef file contains an error. It defines the rich text class using ctxt as its code. That code is also used by AppleScript to define the text class, and the resulting terminology conflict has led to problems. In the Cocoa Scripting Guide, Apple recommends that you instead use ricT as the code for the rich text class. Until Apple places a definitive Text Suite in the /System/Library/ ScriptingDefini- tions folder, I recommend that you use the most recent complete version of the Text Suite, which appears in Apple's ScriptingDefinitions 1.3 sample code. It is available through the Xcode documentation window. It uses the correct ricT code for the rich text class, and it uses TEXT as the code for the Text Suite instead of ???? . 542 Reci pe 1 2 : Ad d Ap p leS c rip t S up p o rt