# develop-28 9612 December 1996 — source transcripts, page 1

[Canonical transcript page](https://www.vintageapple.net/transcripts/media/va-develop-28-9612-december-1996-d696b1/1)

## Transcribed source material

Machine transcriptions and image descriptions; uncertain copy may be marked [illegible]. Verify against the linked originals. Historical rights remain with the original owners.

These are transcribed excerpts, not the full publications. Open the originals for remaining pages.

### Image 1

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-28-9612-december-1996-d696b1/1#scan-8956cc491a59fd7fe5c29d421ac507d68b3b45cf39f11bdfa41f26d52b48ebee)

Transcribed text:

OpenDoc Memory Management • Safe Printing • Source Code Control

develop

The Apple Technical Journal

Issue 28 December 1996

Coding Your Object for Advanced Scriptability

New QuickDraw 3D Geometries

QuickDraw GX Line Layout: Bending the Rules

MacApp Debugging Aids

Chiropractic for Your Misaligned Data

$10.00

Image description: A magazine cover with a blue top banner, a large black script 'develop' logotype, and a left column of red and black headlines beside a surreal illustration of a wooden marionette-like robot with a monitor head, suspended from crossed handwritten sheets, against a blue sky with a flag and light bulbs.

Reading notes: Small text at the bottom of the left column and handwritten text on the crossed sheets in the illustration are not fully legible and were not transcribed. Apple logo is a graphic mark with no text.

Printed product names: develop · The Apple Technical Journal

Printed prices: $10.00

Printed dates: December 1996 · Issue 28

Languages: English

[Original Image 1](https://www.vintageapple.net/files/0af19d51ca3e62dcf2bf066a2b71f74079d53851cfbe91046363cb4bbdb118a9/b99aeb299ee5459b501308e4.webp)

### PDF page 1

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-28-9612-december-1996-d696b1/1#scan-eaf78317ac5009f00a1868c2090b14fea977ad8a1a5117a2a5a909700aa5074d)

Transcribed text:

OpenDoc Memory Management • Safe Printing • Source Code Control

develop
The Apple Technical Journal
Issue 28 December 1996

Coding Your Object for Advanced Scriptability

New QuickDraw 3D Geometries

QuickDraw GX Line Layout: Bending the Rules

MacApp Debugging Aids

Chiropractic for Your Misaligned Data

$10.00

Image description: A magazine cover with a blue top banner, the italic 'develop' logo with an Apple logo, a left column of red and black cover-line headlines, and a right illustration of a wooden marionette-like figure with a CRT monitor head and circuit-board torso hung from strings held by a hand, set against a blue sky with a circle diagram, light bulbs, and a red curtain.

Reading notes: The small text on the marionette's arms and the handwritten-style text on the crossbars is decorative and not transcribed. Reading order of cover lines is top to bottom in the left column; the top banner text is treated as first.

Printed product names: develop · QuickDraw 3D · QuickDraw GX · MacApp

Printed prices: $10.00

Printed dates: December 1996

Languages: English

[Original PDF page 1](https://www.vintageapple.net/files/76fab0ce159489efc741b347ef3b3f876fd261021de3a38b4e3f9ed49633399c/develop-28_9612_December_1996.pdf#page=1)

### PDF page 2

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-28-9612-december-1996-d696b1/1#scan-debb2e45e87ed85660ad4b5ecf2f10c1ea0b8363389e16730183cbe99554bf9f)

Transcribed text:

Printed on recycled paper by
Stream International, USA
T H I N G S   T O   K N O W
develop, The Apple Technica l Journa l,   a quarterly publication of the
Apple Developer Relations group, is published in March, June, September, and
December. It provides developers of Apple-platform products with technical
articles and code that have been reviewed for robustness by Apple engineers.
All issues of   develop,   along with the code they describe, can be found on the   develop
Bookmark   CD, the Reference Library edition of the   Developer CD Series , and the
Internet. The code is updated regularly, so always use the latest version.
This issue’s CD.   Subscription issues of   develop   are accompanied by the   develop
Bookmark   CD. This CD contains a subset of the materials on the   Developer CD Series ,
which is part of the Apple Developer Mailing available through the   Apple Developer
Catalog . The CD also contains Technotes, sample code, and other documentation
and tools (these contents are subject to change). Items referred to as being on “this
issue’s CD” are located either on the Bookmark CD or on the Reference Library or
Tool Chest edition of the   Developer CD Series .
Subscriptions and back issues.   You can subscribe to   develop   through the
Apple Developer Catalog   (see below, or use the subscription card in this issue). Back
issues, in addition to being available electronically, can also be ordered through the
catalog. The one-year U.S. subscription price is $30 (for four issues and four   develop
Bookmark   CDs), or U.S. $50 in other countries. Back issues are $13 each. These prices
include shipping and handling. For Canadian orders, the subscription price includes
GST (R100236199).
W H E R E   T O   F I N D   U S
What   Who/where
develop   on the Web   http://www.devworld.apple.com/develop/
and ftp   ftp://ftpdev.info.apple.com/Developer_Services/
Periodicals/develop/
Bookmark CD contents   http://www.devworld.apple.com/
ftp://ftpdev.info.apple.com/Developer_Services/
Technotes on the Web   http://www.devworld.apple.com/dev/technotes.shtml
Editorial comments   Caroline Rose, crose@apple.com, (408)974-0544 fax
or suggestions
Technical questions   Dave Johnson, dkj@apple.com, (408)974-0544 fax
about   develop
Article submissions   develop@apple.com (ask for our Author’s Kit)
Apple Developer Catalog   http://www.devcatalog.apple.com
( develop   subscription, back   order.adc@applelink.apple.com
issues, or other products)   1-800-282-2732 U.S., 1-800-637-0029 Canada
(716)871-6555 internationally, (716)871-6511 fax
Apple Developer Catalog , Apple Computer, Inc., P.O. Box
319, Buffalo, NY 14207-0319
Subscription changes or   order.adc@applelink.apple.com
queries   Please be sure to include your name, address, and account
number as they appear on your mailing label.
E D I T O R I A L   S T A F F
Editor-in-Cheek   Caroline Rose
Managing Editor   Stacy Fields, Toni Moccia
Technical Buckstopper   Dave Johnson
Our Boss   Steve Strong
His Boss   Garry Hornbuckle
Bookmark CD Leader   Alex Dosher
Review Board   Brian Bechtel, Dave Radcliffe,
Quinn “The Eskimo!”, Jim Reekes,
Bryan K. “Beaker” Ressler, Larry Rosenstein,
Nick Thompson, Gregg Williams
Contributing Editors   Lorraine Anderson,
Toni Haskell, Cheryl Potter, Erik Sea,
George Truett
Indexer   Marc Savage
A R T   &   P R O D U C T I O N
Art Direction   Lisa Ferdinandsen
Technical Illustration   John Ryan
Formatting   Forbes Mill Press
Production   Diane Wilcox
Photography   Sharon Beals, Leilani Coe,
Adrienne Gersnoviez
Cover Illustration   Cary Henrie
ISSN #1047-0735. © 1996 Apple Computer,
Inc. All rights reserved. Apple, the Apple logo,
AppleScript, AppleTalk, ColorSync, LaserWriter,
Mac, MacApp, Macintosh, Macintosh Quadra,
MacTCP, MessagePad, MPW, MultiFinder,
Newton, OpenDoc, Power Mac, Power Macintosh,
PowerTalk, QuickTime, StyleWriter, and
TrueType are trademarks of Apple Computer,
Inc., registered in the U.S. and other countries.
AOCE, A/ROSE, Balloon Help, develop, Dylan,
Finder, NewtonScript, ToolServer, and
QuickDraw are trademarks of Apple Computer,
Inc. Adobe and PostScript are trademarks of
Adobe Systems Incorporated or its subsidiaries
and may be registered in certain jurisdictions.
QuickView is licensed from Altura Software, Inc.
PowerPC, SOM, and SOMobjects are trademarks
of International Business Machines Corporation,
used under license therefrom. UNIX is a
registered trademark in the United States and
other countries, licensed exclusively through
X/Open Company, Ltd. All other trademarks
are the property of their respective owners.

Reading notes: Transcript is intentionally empty because the exact extracted text is preserved separately, so the fields above were filled from the supplied copy only. Headline is taken from the spaced-out section heading and may not match the printed layout exactly. Spacing artifacts such as split words (Technica l Journa l) and split product names around the bookmark CD line may reflect extraction rather than print. The Where to Find Us table and the editorial staff list have column alignment that could not be verified from the copy alone. Staff name and joke titles such as Editor-in-Cheek and Technical Buckstopper are reproduced as printed in the supplied copy. The GST registration number and phone and fax numbers appear in the copy but were not listed as fields since they are not advertised prices or dates.

Printed product names: develop · Bookmark CD · Developer CD Series · Apple Developer Mailing · Technotes · Apple Developer Catalog

Printed prices: $30 · U.S. $50 · $13

Printed dates: 1996 · March · June · September · December

Languages: English

[Original PDF page 2](https://www.vintageapple.net/files/76fab0ce159489efc741b347ef3b3f876fd261021de3a38b4e3f9ed49633399c/develop-28_9612_December_1996.pdf#page=2)

### PDF page 3

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-28-9612-december-1996-d696b1/1#scan-9f24daded36a3993294424e2b0059d16093290e8c6bf794b31ea98b2ded7896e)

Transcribed text:

A R T I C L E S
4   Coding Your Object Model for Advanced Scriptability   by Ron Reuter
Basic support for an Apple event object model isn’t too tough, but supporting more complex scripts takes some
planning, and can trip you up in subtle ways if you’re not careful. This advice will help you out.
32   New QuickDraw 3D Geometries   by Philip J. Schneider
QuickDraw 3D 1.5 includes several useful new geometric primitives. This article introduces the new primitives
and discusses the differences among the various polyhedral primitives, both new and old.
60   QuickDraw GX Line Layout: Bending the Rules   by Daniel I. Lipton
The typographic capabilities of QuickDraw GX are without peer, but until now drawing that beautiful text
along an arbitrary path took a concerted effort. Here’s a library that makes it easy to do.
76   MacApp Debugging Aids   by Conrad Kopala
Programming with a framework saves time and effort, but debugging can be difficult, since there’s a lot going
on beneath the surface. These techniques for detecting problems in MacApp programs can help.
91   Chiropractic for Your Misaligned Data   by Kevin Looney and Craig Anderson
Misaligned data accesses on PowerPC processors can be very expensive. Two tools that will help you detect
misalignment problems are presented here, along with some advice on avoiding misalignment in the first place.
C O L U M N S
28   THE OPENDOC ROAD
OpenDoc Memory Management and the
Toolbox
by Troy Gaul and Vincent Lo
Managing memory allocation in your OpenDoc
part editor can be a little tricky.
56   PRINT HINTS
Safe Travel Through the Printing Jungle
by Dave Polaschek
Printing is often much more complex than it
needs to be. By keeping it simple and staying on
the well-trod path, you can protect yourself.
72   BE OUR GUEST
Source Code Control for the Rest of Us
by D. John Anderson and Alan B. Harper
Source control doesn’t need to be complex, as
the simple tools presented here will show.
88   MPW TIPS AND TRICKS
Automated Editing With StreamEdit
by Tim Maroney
The MPW tool StreamEdit provides you with
powerful, flexible, scriptable text editing, at the
price of just a little complexity.
101   MACINTOSH Q & A
Apple’s Developer Support Center answers
queries about Macintosh product development.
110   THE VETERAN NEOPHYTE
Confessions of a Veteran Technical Writer
by Tim Monroe
Enlightening trade secrets from someone who
writes the documentation we all depend on.
113   NEWTON Q & A: ASK THE LLAMA
Answers to Newton-related development
questions. Send in your own questions for a
chance at a T-shirt.
118   KON & BAL’S PUZZLE PAGE
Folder Fun
by Konstantin Othmer and Bruce Leak
Is a puzzle without a solution really a puzzle?
Only you can decide. Those divas of debugging
run us through the wringer once again.
2   EDITOR’S NOTE
3   LETTERS
123   INDEX
Issue 28   December 1996
CONTENTS   1

Printed product names: QuickDraw 3D 1.5 · QuickDraw GX · MacApp · PowerPC · OpenDoc · MPW · StreamEdit · Newton · Macintosh

Printed dates: December 1996

Languages: English

[Original PDF page 3](https://www.vintageapple.net/files/76fab0ce159489efc741b347ef3b3f876fd261021de3a38b4e3f9ed49633399c/develop-28_9612_December_1996.pdf#page=3)

### PDF page 4

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-28-9612-december-1996-d696b1/1#scan-16ed9c02d1b3d293c1d898a92b08b8af65e54af6c85dd37f148f697c28d021ba)

Transcribed text:

Regular readers of   develop   may know that, while I always use the latest hardware and
software at work, my home system is woefully out of date — at least it was until I
recently upgraded to a Power Mac. The initial setup wasn’t too hard, once I got used
to flipping back and forth between the manual for the computer, the manual for the
monitor, and the online updates; when all else failed, I relied on common sense. But
when I moved beyond hardware setup into software installation, it seemed as if I was
expected to know much more than I did. The modem software installer, for example,
would just name a software module and say “click OK if you want to install this,”
with no mention of which module(s) provided the basic modem capabilities (which is
all I wanted). What to do? I recently had this same feeling while trying to learn a new
e-mail application at work: though I immediately saw how to address mail to anyone
on any network in the known world with barely a keystroke, I couldn’t tell how to
simply enter an address for someone here at Apple. In these and many similar cases
I’ve encountered recently, I couldn’t figure out how to perform basic application
functions without the intervention of an experienced user. The manuals and online
help were somewhat helpful, but they were limited by the design of the software,
which was the problem in the first place. Common sense was no help at all.
Naturally I griped about this to my “friends in the industry.” I think one of them hit the
nail on the head when he said the problem is that too many products are being designed
by experts who, consciously or not, design for experts. Designing with experts in mind
ends up complicating everything, even the features that should be simple. Bud Tribble,
when he managed the software group at NeXT, used to tell programmers, “Simple things
should be simple, and complex things should be possible.” It seems increasingly true these
days that designers are trying to make complex things simple, but as a result are making
simple things complex. Design by experts for experts is not the answer: developers need to
find out what real users want, and focus on   their   needs.
Is   develop   guilty of a similar problem? When I looked at the feedback we gathered at
Apple’s Worldwide Developers Conference this year, I noticed that some   develop   readers
are asking for more entry-level articles, saying that a lot of what we publish is over their
heads. While we’re limited by what types of articles are submitted to us for publication,
the   develop   Review Board does get to say which ones are accepted or not, and the Board
is largely made up of “expert” programmers. Do we consequently tend to decide in
favor of the more advanced articles? We’ll keep an eye out for this from now on.
I often recall the days when Steve Jobs envisioned that the Macintosh would be as easy to
use as a home appliance. Sure, we don’t want to go back to that first oversimplified
product, but maybe we should all ponder whether we’ve gone a bit too far in the opposite
direction. I’d like to believe there’s still a place for common sense.
CAROLINE ROSE
develop   Issue 28   December 1996 2
EDITOR’S NOTE
CAROLINE ROSE   (crose@ apple.com) has been
a Mac enthusiast ever since she started writing
the original   Inside Macintosh   in 1982. After a
reorganization that suddenly changed the entire
managerial hierarchy above her (up to and
including Steve Jobs), she left Apple, but like so
many other formerly disgruntled employees, she
eventually returned. This year, again, a reorg
happened that changed the entire managerial
hierarchy above Caroline. At least there’s some
stability in her home life, where her cat Cleo
remains the boss after 15 long years.•
Caroline Rose
Editor

Reading notes: Possible reading-order ambiguity where the Editor's Note sidebar is interleaved with the main text.

Printed product names: Power Mac · Inside Macintosh · Macintosh

Printed dates: 1982 · December 1996 · 1996

Languages: English

[Original PDF page 4](https://www.vintageapple.net/files/76fab0ce159489efc741b347ef3b3f876fd261021de3a38b4e3f9ed49633399c/develop-28_9612_December_1996.pdf#page=4)

### PDF page 5

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-28-9612-december-1996-d696b1/1#scan-c888f9b6f20e3e3f0deba134c1f141d49091cf6db9dce005ffffe1e12817a9cc)

Transcribed text:

GAME OUT OF CONTROL
When running the code from Philip
McBride’s article “Game Controls for
QuickDraw 3D” in Issue 27 of   develop,   I
noticed in MySetCameraData that the
call to Q3Camera_SetPlacement gets
fouled up after a while. The fix shown
below was needed.
v oi d   M y Get Cam er aDat a(
Doc um ent Pt r   t heDoc um ent ,
TQ3Cam er aObj ec t   t heCam er a)
{
TQ3Cam er aPl ac em ent   c am er aPl ac em ent ;
. . .
Q3Vec t or 3D_Cr os s (
&t heDoc um ent - >z Vec t or ,
&t heDoc um ent - >y Vec t or ,
&t heDoc um ent - >z Vec t or ) ;
/ /   I   added   t hi s :
Q3Vec t or 3D_Nor m al i z e(
&t heDoc um ent - >x Vec t or ,
&t heDoc um ent - >x Vec t or ) ;
}
— Flip Phillips
You made the right call. QuickDraw 3D
requires all vectors to be of unit length
(normalized). So any changes to vectors that
could make them not normalized should be
followed by a call to normalize those vectors
(using Q3Vector3D_Normalize as you’ve
done). If QuickDraw 3D didn’t have this
requirement, it would have to normalize
vectors itself internally, which would take
away from its efficiency.
— Philip McBride
A SIDE ISSUE
In Steve Falkenburg’s article “Planning
for Mac OS 8 Compatibility” in   develop
Issue 26, I read the following:
After some poking around, we figured
out that it was assuming that
InitWindows called InitMenus as a side
effect. The completely new Mac OS 8
implementations of windows and menus
no longer have this behavior.
However,   Inside Macintosh   Volume V
states, under the heading “InitWindows”
on page 208:
Since the menu bar definition procedure
('MBDF') actually performs these
calculations, InitWindows now calls
InitMenus directly. InitMenus has been
modified so that it can be called twice
in a program without ill effect.
I advise the Mac OS 8 engineers to read
the “You’re never too smart to read the
manual” section of the Veteran Neophyte
column in the same issue of   develop   ;-).
— Reinder Verlinde
Your point is well taken. However, it’s
worth mentioning that Inside Macintosh:
Macintosh Toolbox Essentials (the more
current documentation) says no such thing,
and in fact says explicitly that InitMenus
should always be called after InitWindows.
As always, depending on a side effect, even
a documented one, is dangerous.
— Dave Johnson
LETTERS
LETTERS   3
THINK THESE LETTERS ARE BORING?
Then why not write one of your own? We welcome
your letters to the editor, especially regarding
articles published in   develop . W rite to Caroline
Rose at crose@ apple.com or, if technical
develop -related questions, to Dave Johnson at
dkj@ apple.com. All letters should include your
name and company name as well as your address
and phone number. Letters may be excerpted or
edited for clarity (or to make them say what we
wish they did). Address subscription-related
queries to order.adc@ applelink.apple.com.•
Look on this issue’s CD and   develop ’s
Web site for Martin Minow’s article,
“ Timing on the Macintosh,” which
was recently updated to include a
few Java timing techniques. You’ll
also find some scripting vocabulary
advice from Cal Simone.
MORE GOOD STUFF

Reading notes: Code listing line breaks may affect reading order of the MySetCameraData snippet

Printed product names: QuickDraw 3D · Mac OS 8 · Inside Macintosh · Inside Macintosh: Macintosh Toolbox Essentials · develop

Printed dates: Issue 27 · Issue 26 · Volume V · page 208

Languages: English

[Original PDF page 5](https://www.vintageapple.net/files/76fab0ce159489efc741b347ef3b3f876fd261021de3a38b4e3f9ed49633399c/develop-28_9612_December_1996.pdf#page=5)

### PDF page 6

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-28-9612-december-1996-d696b1/1#scan-b35c90a08a8e460df6d38f23bf2f00e4789e8d065180defa2aed740c0bb34b26)

Transcribed text:

Implementing an Apple event object model makes your application
scriptable — that is, it enables users to control your application with
AppleScript or some other OSA-compliant language. You can provide
anything from a basic implementation of the object model that handles
only simple scripts to a full implementation that can handle the most
complex scripts. This article will help you do the latter. It will show you
how to write object accessors and handlers that process lists of objects,
alert you to some common pitfalls, and suggest other features you can
add for completeness.
You’ve decided to give your users an alternate interface for controlling your application
by implementing an Apple event object model. You’ve read Richard Clark’s article,
“Apple Event Objects and You,” in   develop   Issue 10 to get an overview of the Apple
event object model and how to support it. As you’ve begun to think about your
scripting vocabulary, you’ve absorbed Cal Simone’s article, “Designing a Scripting
Implementation,” in   develop   Issue 21 and his According to Script column in Issue 24.
You’ve checked out the portions of   Inside Macintosh: Interapplication Communication
that apply. You’ve read and understood the   Apple Event Registry , which defines the
primary events and objects that you should support in a scriptable application, and
have paid particular attention to the Core, Text, and QuickDraw Graphics suites.
With this basic knowledge, you’re ready to read this article. Here you’ll learn how
to structure your code to handle more complex user scripts. After a brief review of
the components of an object model implementation, I’ll focus on object accessors
and show you how to handle script statements that require your code to act on a list
of objects. Then I’ll describe in detail how to deal with three big “gotchas” that
are bound to trip you up unless you know about them. Finally, I’ll tell you about
some other goodies you can implement for the sake of completeness. All of this is
illustrated in the sample application Sketch, which demonstrates object model
support for a subset of the QuickDraw Graphics suite. The code for Sketch, which
accompanies the article on this issue’s CD and   develop ’s Web site, contains many
functions that you can use when you get ready to code the object model for your own
application.
RON REUTER
C oding   Y our Objec t Model for Advanc ed
S c riptability
develop   Issue 28   December 1996 4
RON REUTER   (rlreute@ uswest.com) is a
software developer for USW EST Media Group,
“ a leading provider of Yellow Pages and
interactive multimedia information services” or,
as it used to be known, the phone company. He’s
spent the last two years as technical lead on a
team that’s developing a graphics package to be
used across a fourteen-state region to build ads
for USW EST Yellow Page directories. Programming
is Ron’s sixth career; he’s also been a offset press
operator, a furniture maker, a luthier, a traveling
jewelry salesman, and a Zen student — but he’d
rather be dancing beneath the diamond sky with
one hand waving free.•

Printed dates: December 1996

Languages: English

[Original PDF page 6](https://www.vintageapple.net/files/76fab0ce159489efc741b347ef3b3f876fd261021de3a38b4e3f9ed49633399c/develop-28_9612_December_1996.pdf#page=6)

### PDF page 7

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-28-9612-december-1996-d696b1/1#scan-0308a8c4a6b6e1bedb19514db2846c1a1d5420fa34b97161f228f3eb738caccc)

Transcribed text:

COMPONENTS OF AN OBJECT MODEL IMPLEMENTATION
The components of an object model implementation are outlined in the “Apple Event
Objects and You” article and discussed in great detail in   Inside Macintosh: Interapplication
Communication . Here I’ll briefly review the basic terms and concepts to refresh your
memory and to show how they apply in our sample program.
When a script statement asks your application to perform an action on some object,
such as closing document 1, the object specifier (document 1) must be resolved —
that is, the representation of the specified object must be located in memory. Your
application resolves the object specifier by way of an object accessor function that
converts the object specifier into a token. The token is then passed to an event
dispatcher for that object. I’ll describe each of these components before reviewing
the process of resolving object specifiers and dispatching events.
Object accessors   are functions you write and install in an accessor table. These functions
are called by the Object Support Library (OSL) function AEResolve when the Apple
Event Manager needs to find some object in your application’s data structures. Object
accessors receive a container, an object specifier for an object to locate inside that
container, and a result parameter into which a token is placed. When you install
accessors, you tell the Apple Event Manager that your application knows how to find
a certain kind of object in a certain kind of container. For instance, you know how to
find a rectangle object in a grouped graphic object or a word object in a paragraph
object. (More on containers in a minute.)
A   token   is an application-defined data structure that is populated in your object
accessors and is passed later to your object’s event dispatcher code, where it’s used to
find the object that an Apple event will be applied to. The structure and content of a
token are private to the application; neither the Apple Event Manager nor the OSL
attempts to interpret or use the contents of a token. The Sketch sample application
uses a single token structure, shown below, for all of its objects. Note that some fields
aren’t used for all object types and that the token doesn’t contain the object’s data or a
data value; it contains information about how to locate the object later. You can use a
single token structure in your implementation, or you may want to design a unique
token structure for each object you support.
t ypedef   s t r uc t   Cor eTok enRec or d   {
DescTy pe   di s pat c hCl as s ;   / /   c l as s   t hat   wi l l   handl e   an   ev ent
DescTy pe   obj ec t Cl as s ;   / /   ac t ual   c l as s   of   t hi s   obj ec t
DescTy pe   pr oper t y Code;   / /   r eques t ed   pr oper t y   c ode,
/ /   or   t y peNul l   i f   not   a   pr oper t y   t ok en
l ong   doc um ent Num ber ;   / /   uni que   I D f or   t he   doc um ent ,   or   0
l ong   el em ent Num ber ;   / /   uni que   I D f or   t he   el em ent ,   or   0
W i ndowPt r   wi ndow;   / /   us ed   f or   wi ndow obj ec t s   onl y
}   Cor eTok enRec or d,   * Cor eTok enPt r ,   * * Cor eTok enHandl e;
Event dispatchers   are application-defined functions that you call after you’ve called
AEResolve and your object accessors have returned a token for the target of the
Apple event. You call your event dispatchers and pass the token you created, the
original Apple event, and the reply Apple event you received in your Apple event
handler. The event dispatcher examines the Apple event, extracts the event ID, and
passes its parameters on to a specific event handler for the token object. The token is
used to identify the object or objects that the Apple event should act on.
Apple event handlers   are functions you write and install that receive a specific Apple event
and a reply Apple event. Your event handlers extract parameters from the Apple event,
process the event using those parameters, and place the result in the reply Apple event.
CODING YOUR OBJECT MODEL FOR ADVANCED SCRIPTABILITY   5

Languages: English

[Original PDF page 7](https://www.vintageapple.net/files/76fab0ce159489efc741b347ef3b3f876fd261021de3a38b4e3f9ed49633399c/develop-28_9612_December_1996.pdf#page=7)

### PDF page 8

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-28-9612-december-1996-d696b1/1#scan-a635daad0baf080eefd6f65ab6217b2b707e4eeeb32f20aa1c007eff8d4ee8d8)

Transcribed text:

A single handler can be installed to handle many events. For example, one handler can
receive all events in the Core suite, except the Create Element event, if you specify
kAECoreSuite for the event class and typeWildCard for the event ID. Because
Create Element passes an insertion location instead of an object specifier in the direct
object parameter, Sketch installs a separate handler, AECreateElementEventHandler,
to handle this event for all Core suite objects.
The Sketch sample code resolves object specifiers and dispatches Core suite Apple
events by using the object-first approach. The object-first flow of control proceeds as
follows:
1. In the Core suite event handler, extract the parameter for the direct object of
the Apple event. Except in the case of the Create Element event, this is a
reference to some object the user is trying to access or modify.
2. Call AEResolve, which calls one or more of your object accessor functions,
each of which finds the requested object in a specified container and then
returns a token. AEResolve successively calls object accessors until one of the
following three conditions is met: you return a token for the specified object;
you return an error code; or AEResolve finds a container-element combination
for which there’s no installed accessor.
3. Examine the token to determine what kind of object it references and then
send the original event, the reply event, and the token to the event dispatcher
for that type of object.
4. In the object’s event dispatcher, extract the event ID and dispatch the event
and the token to the object’s event handler.
5. In the object’s event handler, apply the event to the object or objects
referenced by the token and return the results in the direct object of the
reply Apple event. You usually just unpack the parameters in your event
handler and then call lower-level functions you’ve written to do the
application-specific work.
Figure 1 shows how this approach is applied as Sketch processes the script statement
s et   f i l l   c ol or   of   r ec t angl e   1   of   doc um ent   1   t o   bl ue
Note that Sketch has one file for each type of scriptable object. Figure 1 shows
fragments of three files:
•   AECoreSuite.c, which receives all Apple events from the Core suite, resolves
the direct object parameter, and dispatches the token and the Apple event to
the dispatcher for a specific object type
•   OSLClassDocument.c, which contains accessors, a dispatcher, and event
handlers for document objects
•   OSLClassGraphicObject.c, which contains accessors, a dispatcher, and event
handlers for all graphic objects
OBJECT ACCESSORS AND YOUR CONTAINMENT
HIERARCHY
How you implement your object model will depend largely on the nature of your
data and on your containment hierarchy. Your containment hierarchy specifies the
objects you support, how script statements should address those objects, and which
objects are contained by which other objects. Contained objects are called   elements   of
the container object. Each object also usually contains one or more   properties , which
develop   Issue 28   December 1996 6

Reading notes: Source appears to be a technical article, possibly truncated at the end ("which develop"). Some source text has irregular character spacing in the script example ("s et   f i l l   c ol or"), which may be a typographic artifact.

Printed dates: December 1996

Languages: English

[Original PDF page 8](https://www.vintageapple.net/files/76fab0ce159489efc741b347ef3b3f876fd261021de3a38b4e3f9ed49633399c/develop-28_9612_December_1996.pdf#page=8)

### PDF page 9

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-28-9612-december-1996-d696b1/1#scan-6fde4a4f880e7d484773c1ac073c4e227b6ee92ca0ae7995b09480ccf5e0a14a)

Transcribed text:

represent that object’s characteristics, such as font size or color. While an object can
contain many elements of a particular type, it contains only one of each of its
properties. A script identifies the object to inspect or change by way of an   object
reference , which specifies the object’s location in the containment hierarchy.
Sketch has the containment hierarchy shown in Figure 2. The application object can
contain both windows and documents. Documents, in turn, contain objects defined in
the QuickDraw Graphics suite, such as rectangles, ovals, graphic lines, and graphic
groups. Graphic groups can contain any object from the QuickDraw Graphics suite,
including other graphic groups.
The following complete script navigates through Sketch’s containment hierarchy
from top to bottom to get a property of an object:
t el l   appl i c at i on   " Sk et c h"
t el l   doc um ent   " Sal es   Char t "
t el l   r ec t angl e   1
get   f i l l   c ol or
end   t el l
end   t el l
end   t el l
CODING YOUR OBJECT MODEL FOR ADVANCED SCRIPTABILITY   7
AECoreSuiteEventHandler
Extract the direct
object parameter.
Call AEResolve,
which calls three
object accessors.
Examine the token to
determine which object
should handle the event.
It‘s a property of
rectangle token, so call
the event dispatcher for
graphic objects.
GraphicObjectFromDocumentAccessor
Receives a document token and
returns a rectangle token.
…
PropertyFromGraphicObjectAccessor
Receives a rectangle token and
returns a property of rectangle token.
…
GraphicObjectEventDispatcher
Examine the Apple event to get
the event ID. It‘s kAESetData, so
call this object‘s Set Data event
handler.
…
HandleSetData
Receives a token and a reply event.
The token contains a property code for
the fill color property of rectangle 1.
The keyData parameter of the event
contains the data representing “ blue.”
Use the token data to change the
rectangle‘s color to blue.
DocumentFromApplicationAccessor
Receives an application token and
returns a document token.
AECoreSuite.c   OSLClassDocument.c
OSLClassGraphicObject.c
1
2
3
4
5
Figure 1.   How Sketch processes   set fill color of rectangle 1 of document 1 to blue

Reading notes: Source text is a technical manual excerpt about Sketch object model scripting, not an advertisement; no advertised products or prices present Text includes spaced-out letters and figure-label fragments from extraction that may affect reading order

Languages: English

[Original PDF page 9](https://www.vintageapple.net/files/76fab0ce159489efc741b347ef3b3f876fd261021de3a38b4e3f9ed49633399c/develop-28_9612_December_1996.pdf#page=9)

### PDF page 10

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-28-9612-december-1996-d696b1/1#scan-523eeab0fc88f1e3b3e12f6594baada18d78b1fb2a24ff5e63d99e265ec06e99)

Transcribed text:

Throughout the rest of this article, I’ll usually show script fragments consisting of a
single statement instead of complete scripts.
The desired object can be specified in one of several ways in a script statement, as
you’ll see later in the discussion of key forms. Theoretically, for each container-
element combination in your containment hierarchy, you need an object accessor
function that can find the element type in its container type. In reality, you frequently
can get by with a single object accessor function that can handle many container-
element pairs, rather than having to write and install a separate function for each one.
The   Apple Event Registry   lists the elements that can be contained within each object it
defines. Recursive definitions occur frequently in the Registry. For example, the word
object in the Text suite can contain characters, words, lines, paragraphs, and text.
While it seems reasonable that a word can contain a character, when would a word
contain a line or a paragraph? Suppose the script asked to do something to words 1
through 200. This is an example of a range specifier, which we’ll look at in more
detail later. Your application might resolve this range specifier into a list of 200 word
objects. Because there could be many paragraphs within that range, asking for
paragraph 2 of words 1 through 200 would make sense. It’s to support range specifiers
that every text object is required to be an element of every other text object.
The upshot of this is that to support the word object in the Text suite, you would need
to write object accessors to resolve all these possible containment scenarios: word-from-
character, word-from-word, word-from-line, word-from-paragraph, word-from-text,
and either word-from-document (for a text editor that supports one large text object
per document) or word-from-graphic-text (for a drawing application that supports
many text boxes per document). As mentioned earlier, though, you frequently can get
by with a single object accessor function that can handle many container-element
pairs. Sketch, for example, uses just two object accessors to support all objects in
the QuickDraw Graphics suite: GraphicObjectFromDocumentAccessor and
develop   Issue 28   December 1996 8
graphic object
application
graphic line
graphic object
graphic group…
oval graphic group
polygon
rectangle document
rounded rectangle
window
graphic line
oval
polygon
rectangle
rounded rectangle
Figure 2.   The Sketch containment hierarchy

Reading notes: Source text includes 'develop Issue 28 December 1996' running footer, the only printed date present.

Printed dates: 1996

Languages: English

[Original PDF page 10](https://www.vintageapple.net/files/76fab0ce159489efc741b347ef3b3f876fd261021de3a38b4e3f9ed49633399c/develop-28_9612_December_1996.pdf#page=10)

### PDF page 11

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-28-9612-december-1996-d696b1/1#scan-9c3163fda0424660594bcde7413e94837b1476465c967f78e31d9ac84603ea72)

Transcribed text:

GraphicObjectFromGroupAccessor, both of which call GraphicObjectAccessor to do
the real work of finding a graphic object.
OBJECT ACCESSORS AND KEY FORMS
Script statements can ask for an object or a collection of objects in a variety of ways.
They can ask for a single object by its unique ID, by name, or by its absolute or
relative position in a container. A script can also ask not for an object, but for some
property of an object, such as the fill color of a rectangle or the font of a paragraph.
A script statement can ask for more than one object by using the word   every , by
specifying a range between some object and some other object in a container, or by
specifying a test that the objects must satisfy. The method that’s used to reference an
object or objects in a script determines the keyForm parameter that an object
accessor function will receive when it comes time to resolve the object specifier.
When an object accessor receives one of the simple key forms and associated key data
types listed in Table 1, it returns a descriptor containing a token that references a
single object in your application. When it receives one of the complex key forms and
associated key data types listed in Table 2, it returns a descriptor containing a list of
tokens, each of which references a single object.
Note that not all key forms are appropriate for all classes — a rectangle might not
have a name, for example, and some objects, such as a word or a paragraph, might not
have a unique ID. According to   Inside Macintosh: Interapplication Communication , if a
key form isn’t supported for an object in one of your containers, you should return
errAEEventNotHandled. But you might want to return a more specific error code,
such as errAEBadKeyForm or errAENoSuchObject.
HANDLING SIMPLE KEY FORMS
Handling the simple key forms is mostly straightforward. Table 3 shows some
examples of script fragments using simple keys and their results. For these examples,
CODING YOUR OBJECT MODEL FOR ADVANCED SCRIPTABILITY   9
Table 1.   Simple key forms
Key form   Key data type   Key data value
formUniqueID   typeLongInteger   A unique number
formPropertyID   typeEnumerated   An identifier declared in your 'aete'
resource
formN ame   typeIntlT ext   The name of an object, such as a
document
formAbsolutePosition   typeLongInteger   A positive or negative number
typeAbsoluteOrdinal   kAEFirst, kAEMiddle, kAELast, kAEAny
formRelativePosition   typeEnumerated   kAEN ext, kAEPrevious
Table 2.   Complex key forms
Key form   Key data type   Key data value
formAbsolutePosition   typeAbsoluteOrdinal   kAEAll
formRange   typeRangeDescriptor   See section “ Handling formRange.”
formT est   See section “ Handling formT est and formW hose.”
formW hose   See section “ Handling formT est and formW hose.”

Reading notes: Source is a technical programming manual excerpt rather than an advertisement; no headline or advertised products or prices are present. Printed text has spacing artifacts such as 'N ame' and 'T ext' that may reflect OCR or extraction spacing issues. Table 3 is referenced but its content is not included in the supplied copy.

Languages: English

[Original PDF page 11](https://www.vintageapple.net/files/76fab0ce159489efc741b347ef3b3f876fd261021de3a38b4e3f9ed49633399c/develop-28_9612_December_1996.pdf#page=11)

[Next transcribed scans](https://www.vintageapple.net/transcripts/media/va-develop-28-9612-december-1996-d696b1/2.md)
