Re: Snow Leopard AppleScript Release Notes
Re: Snow Leopard AppleScript Release Notes
- Subject: Re: Snow Leopard AppleScript Release Notes
- From: Christopher Nebel <email@hidden>
- Date: Tue, 1 Sep 2009 13:07:18 -0700
On Sep 1, 2009, at 11:34 AM, has wrote:
On 28 Aug 2009, at 23:50, Christopher Nebel wrote:
On Aug 28, 2009, at 1:41 PM, has wrote:
3. The ASObjC release notes provide some information on the AS-
ObjC bridging. Offhand, one thing I don't see is covered is
implementing class methods in AppleScript. (The docs state
"AppleScript handlers defined in the 'script' block are equivalent
to the **instance** methods of an Objective-C object" [my
emphasis].) Am I correct in thinking this is not supported?
I should fix that sentence. In fact, a handler serves as both an
instance method *and* a class method; you can invoke it either way.
OK. What if you need to define both class and instance methods with
the same name? (I don't know what the chances of needing to do that
are, but it'd be good to clarify the corner cases.)
At least for now, you can't.
- Can AppleScript 'classes' inherit from other AppleScript
'classes' using the 'property parent : class "CLASSNAME"'
mechanism? If not, can they still inherit via the traditional
AppleScript approach?
I believe that both work, though in the former case you have to be
careful about load order.
How would you control the load order? Presumably putting multiple
script objects in the same file would work. What about if they're in
different files?
You could name the files in alphabetical order, but that's not
guaranteed to work for all file systems. Even within the same file,
I'm not sure we can guarantee the load order. (It's fine for now, I'm
talking long-term.) I'll have to look closer at this one and see if
we can make it Just Workâ˘.
- When mutable objects cross the bridge, are they copied or
shared? I'm assuming they're shared, yes?
Shared. Obj-C objects stay Obj-C objects when they cross; there is
no automatic "boxing" of, say, NSStrings to AppleScript text.
OK. So if AppleScript receives an NSString, can you ask for
character/word/paragraph elements using standard AppleScript idioms,
or do you have to coerce it to an AppleScript text object first, or
are you limited to using its Cocoa methods? And what about
AppleScript objects that cross to the ObjC side?
The answer to that varies some depending on the class involved. When
an AppleScript method gets a Cocoa object, it stays a Cocoa object
until you explicitly coerce it using "as". (For example, "as text".)
In the case of NSString, there is no automatic bridging of "text"
accessors, so you'd have to use characterAtIndex_(n) rather than
"character". There is some automatic bridging for collections,
however: "item n of" and "count" work on NSArrays and NSDictionaries,
which means you can do "repeat with i in anNSArray" and it will work,
and "property of ..." is bridged into a -valueForKey: call, which
means it works on any KVC-compliant class, notably NSDictionary.
Oh, and one other question: am I right in thinking there's no way to
access Cocoa via AppleScriptObjC outside of an Xcode project? e.g.
In Python, you can bring in PyObjC at any time with a simple
'import' statement, which is handy if you're writing a batch
processsing script (for which a full-blown app would be complete
overkill) that just needs to tap Cocoa for a bit of functionality.
Currently, that's correct, but we're aware of the desire.
--Chris Nebel
AppleScript Engineering
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden