Developer Documentation
PATH  Mac OS X Documentation > Making Your Applications Scriptable

Making Your Applications Scriptable

Previous | Chapter contents | Next | Book PDF

Use the Document Architecture

Overview

The Application Kit provides a few classes that underpin the Yellow Box's document architecture: NSDocument, NSDocumentController, and NSWindowController. These classes directly implement the standard AppleScript document scripting model. If you use these classes to implement a document-based application, that application automatically supports scripting by a number of AppleScript commands, including Open, Close, and Save. To acquire this scriptability, you need do nothing more than use the document architecture as it was designed.

Applications that take advantage of the Yellow Box's document architecture put themselves in a better position to support scripting generally. A document in Yellow Box applications (NSDocument) typically owns and manages one or more model objects of the application. It therefore provides a hub for scripted access to the model objects in your application, which are the ones that should be scriptable.

For a discussion of the Application Kit's document architecture, see " Application Design for Scripting, Documents, and Undo ."

What You Must Do

Documents are represented by an NSDocument object. To implement a document-based application, you must, first and foremost, create a subclass of NSDocument that gives documents knowledge of the application's model layer and that loads and saves document data. NSWindowController objects manage the user-interface associated with documents. Simple applications can use the default NSWindowController object, but typically you subclass NSWindowController to give window controllers specific knowledge of the user interface they're supposed to manage. In your NSDocument subclass, you then override the makeWindowControllers method to create the window controllers used by the document. Finally, there is the NSDocumentController shared instance, which tracks and manages documents and performs common functions of application delegates (handling application termination, for example). You shouldn't need to subclass NSDocumentController.

For a detailed discussion of what you must do to implement a document-based application, see the reference documentation for the NSDocument class.


Making Your Applications Scriptable

Previous | Chapter contents | Next | Book PDF