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:

> There are several AppleScript documents at the Apple developer web
> site. One is "Guidelines for Creating Scriptable Applications".
> Suppose you already have a pure Objective-C Cocoa app with no
> internal scripts but just Objective-C and C++ code and you want to
> add AppleScript support. It seems like you have to do the following.
>
> 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

This is correct.

But it has nothing to do with AppleScript Studio. Studio allows you to write
Cocoa applications using (mostly) AppleScript as your development language.
A Studio app is itself scriptable, using the built-in Studio dictionary,
which is quite large but not very focused.

The rest of this message focuses on writing a scriptable Cocoa application
using Objective-C, so I'm copying it to the applescript-implementor's list
where this aspect of the discussion should continue.

It isn't easy, but that's only because the documentation isn't yet at the
level of a good tutorial. The documentation is currently more in the form of
a large number of widely scattered reference documents. You have to locate
all of them (which is no easy task), read all of them, organize them into
some sensible order, then read them again. Then you can begin coding, and
you will have to read some of the documents again several times while you
use good old trial and error to get the details right.

I've been AppleScripting for 10 years, and I've been writing applications
for much longer than that, but I only tackled making an application
scriptable a couple of weeks ago for the first time. At first it felt
hopeless, because I couldn't make any sense of it, and I couldn't make a
single piece of the puzzle work. Then it started to fall into place, a piece
at a time, and now, two weeks later, I have a functioning scriptable Cocoa
application with a good dictionary. This was in my spare time (I'm a
full-time trial lawyer), so it isn't really all that difficult.

I, too, noticed that the weakest part of the documentation is how to
implement methods for the Apple events you define in your script suite
definitions and terminology.

Based on my experience, I recommend you take things in this order (this
assumes Panther):

1. Turn on scripting in your application by setting the appropriate Xcode
build setting, which is well documented in several places.

2. Work out a simple design specification for a single AppleScript class in
your application, with a single property, plus one command, and plan to make
these work correctly from start to finish before you tackle your whole
suite.

3. Implement your script suite definition and terminology. There are two
tools that will make this easier for you; take your pick. Both of them have
learning curves, but they come with instructions and examples that are quite
helpful. One is Don Briggs's SuiteModeler
<http://homepage.mac.com/donbriggs/>, which lets you build up your script
suite definition and terminology in a table.

The other is Apple's sdp command line tool, which is what I used. To read
the sdp documentation, launch Terminal.app, type "man sdp" (without the
quotes), and press return. You can also read it in Xcode with its Help >
Open Man Page command, but it is formatted more legibly if you use
Terminal.app (Xcode doesn't yet honor the indentation, which is very
important to understanding the document). You will also need to open "man
sdef", which is a reference to the sdef XML format that the sdp tool
requires and from which it generates the script suite definition and
terminology files for you.

It is hard to create an sdef XML file in a text editor, so you are well
advised to find an XML Editor. I used XML Editor
<http://www.elfdata.com/index.html>, a REALbasic application that works
pretty well (but still has many user interface quirks that make it harder to
use than it should be). Even with Apple's documentation of sdef/sdp and a
good XML editor, it will take you some hard work to get your suite
definition and terminology to look right in your favorite script editor. It
takes a lot of trial and error to get the usage right (a good tutorial would
be a godsend!), and I highly recommend that you very frequently look at your
developing dictionary in your script editor.

If you are running Panther and your application doesn't have to be backwards
compatible, I highly recommend that you use the sdp tool's -V10.3 option,
because it generates more correct terminology.

Study all of Apple's sdef examples, on your disk at
/Developer/Examples/Scripting Definitions. They are very helpful.

Be sure to make use of the "cocoa" element in your sdef files. It makes it
much easier to control the naming of your Cocoa methods that will be
triggered in your finished application. This will get you past the lack of
documentation about methods.

(I will continue this in a second message, since this is so long.)

--

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.