Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Apple Scripting an existing Cocoa Application



on 2003-12-04 7:51 PM, John Richardson at email@hidden wrote:

> Turn On Scripting in the application
> Create Suite Definitions and Suite Terminology
> Implement Scripting Methods (this step is somewhat obscure)
> Define a New Script Command

(Continued from a previous message.)

4. Write the necessary classes and methods into your Cocoa project's source
files. I won't go into much detail here, but just give a few scattered
hints.

First, make sure you understand how the basic key-value coding (KVC)
mechanism works in Cocoa. Reading the developer documentation on key-value
coding may be more confusing than helpful at first, but all you need for now
is an overview of the concept. Basically, the AppleScript system in Cocoa
uses the key-value coding methods -valueForKey: and -takeValue:forKey: (or
their Panther replacements) to call your methods by passing in their names
(as strings) from your script suite definition file. If your methods are
named to correspond to your script suite definition keys, they will get
called when they're supposed to with no further work on your part.

Properties use standard Cocoa naming conventions for "getter" and "setter"
accessor methods. So you'll implement an instance variable for each
property, plus a "getter" method of the same name, plus a "setter" method
beginning with "set..." and followed by the same name with an initial cap.

Commands use whatever you want to name your method, as long as you expose
the name of the method to the AppleScript system by using a "cocoa" element
in your sdef file. Alternatively, you can check the script suite definition
file that was generated by the sdp tool and use the key you see there for
the method name.

It is well worth looking at Apple's Sketch example project, on your disk at
/Developer/Examples/AppKit/Sketch. You will probably have to implement an
-objectSpecifier method in your application, and you'll find examples of it
here (as I recall). It's also worth looking at the TextEdit example project.

There are many more -- and more complex -- facilities available in the Cocoa
frameworks for implementing AppleScript support, but you probably won't need
to delve into them at first, when all you want to do is to get some simple
scriptability set up.

5. Go through the edit-compile-test cycle a kazillion times until it all
works, making frequent reference to the documentation as your understanding,
and therefore your ability to read the documentation correctly, improves.

6. Then add in the rest of your AppleScript terminology.

7. A note on documentation.

AppleScript documentation for developers is a bit of a problem. I think we
would see more widespread AppleScript support in third-party applications if
Apple invested some resources in improving this documentation. As reference
material for somebody who already understands the process, it is mostly
quite good. But a single, detailed tutorial with lots of examples and
explanation of every step is sorely needed.

Here are some hints:

The documentation on the Web site is more up-to-date than what is on your
disk. In particular, I highly recommend reading the October 15 update to the
"Scriptable Applications" document. It is a vast improvement, and it would
have saved me a lot of time if I had realized sooner that this update was
available.

Look through all of the "AppleScript" folders scattered throughout your
/Developer folder. There are lots of them. Some of them are tables of
contents into all the rest of the AppleScript documentation.

Read the class specification document for every Cocoa class whose name
begins with "NSAppleEvent...", "NSAppleScript...", and especially
"NSScript...". There are a few others to read, too, such as those following
the naming pattern "NS...Specifier" and "NS...Command".

Read Andrew Stone's 2000 article "Adding AppleScript Support to Cocoa Apps
<http://www.stone.com>. It's a little obsolete, but there's a lot of meat
there. (You'll have to look around for it; I've lost the exact URL.)

Make use of the mamasam archives of these lists <http://cocoa.mamasam.com/>.
There are lots of tips and sample code snippets in there.

Ask questions on applescript-implementors.

I hope this is helpful to you and others.

--

Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com

The AppleScript Sourcebook - http://www.AppleScriptSourcebook.com
Vermont Recipes - http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
applescript-studio mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-studio
Do not post admin requests to the list. They will be ignored.

References: 
 >Apple Scripting an existing Cocoa Application (From: "John Richardson" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.