AppleScript_ The Definitive Guide - Matt Neuburg [255]
Thus an AppleScript Studio application is automatically scriptable, but only in a messy, disordered way. On the other hand, because an AppleScript Studio application is a Cocoa application, you might wonder whether you can add customized scriptability to your AppleScript Studio application through Cocoa scripting. You can, although there are two major shortcomings to this approach:
Big dictionary
You can add your own suite and your own terms to the dictionary, but you can't at the same time suppress the default AppleScript Studio dictionary. The user might not even notice your custom scriptability amid the vast wash of confusing and useless information.
Communication between languages
It's obvious how AppleScript can talk to Objective-C classes and instances (using call method), but it is far from clear how Objective-C can talk to AppleScript. This is essentially the same problem raised a moment ago; your Objective-C code can't get direct access to the AppleScript script objects that are currently loaded and functioning as the scripts attached to the interface.
With those caveats, it is possible to add Cocoa scripting to an AppleScript Studio application. The procedure is straightforward, except for one thing: you can't use the sdef dictionary format to implement your scriptability. To put it technically, if you add the OSAScriptingDefinition key to your Info.plist, AppleScript Studio itself will break and your application will be stripped of its functionality. Therefore you must implement scriptability the old way, with a resource file. This is not such a terrible thing, as it's what you would have to do in order to implement scriptability for a pre-Tiger application anyway. And besides, you can develop your scriptability using an sdef file; you simply can't implement it with an sdef file in the built application. Thus, as the application is built, you must transform your sdef file into a different format, one that is compatible with earlier systems; and it happens that there's a Unix tool, sdp , that makes this easy to do.
To illustrate, we'll add some basic custom scriptability to the SearchTidBITS application developed earlier in this chapter with AppleScript Studio. The first step is to whip out the Sdef Editor application and create the sdef file. Here it is (for brevity, descriptions are omitted):
The most important thing here is to hook the application class in this file to the existing AppleScript Studio application class. The lines in boldface are absolutely crucial. Get one of these values wrong and the integration between Cocoa scripting and AppleScript Studio will fail. The four-letter code must be 'capp'; the inheritance must specify "ASKApplicationSuite.NSApplication" as the superclass; and the Cocoa class must be "NSApplication."
Save the sdef file as searchTidBITS.sdef. Open the SearchTidBITS project in Xcode and import the sdef file into the project; elect to copy it into the project folder but do not add it to the target. We want this file to live