Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: AppleScript-Cocoa Impedance Mismatch
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AppleScript-Cocoa Impedance Mismatch




On 1 Nov 2007, at 8:42 PM, Major Domo wrote:

I have two impedance mismatches between my sdef and my application, and I'm wondering the best way to deal with them. The application is Leopard-only, so AppleScript 2.0 solutions are A-OK.

First, there are several properties that are lists in AppleScript, but token-delimited strings in the application. What I ended up doing is overriding setValue:forKey: and valueForKey: in the application class, checking for the affected keys, then doing the conversion manually.

While trivial, I'd rather have something that's only activated when used from AppleScript, and generic enough I don't have to implement a bunch of methods for every affected key. Ideally, there'd be scriptingSetValue:forKey: and scriptingValueForKey: methods I could just use, but that doesn't seem to be the case.

Second, we have a class, "medium," that has several different types. In the application, these are all the same class, but in AppleScript, that leads to this rather awkward construction:
make new medium with properties {type:"book",...}
first medium whose type is "book" and...

Creating subclasses in the sdef allows me to "filter out" properties that don't apply to a given medium, so, say, the movie subclass would have cinematographers, but the book subclass would not. However, that still doesn't let me do what I'd really like:
make new book with properties...
first book whose...

Is there a way to translate "book" to "media whose type is book" on the fly, either in the sdef (along the lines of synonyms), or in code? I mean, I guess I could override every single verb, but that seems like a lot of extra work...

Cheers,
Mike Lee, Major-domo
Delicious Monster Software, LLC

Did you have a look at the script support of the Sketch sample project? IIRC it has a graphics element and several subtypes. I think that works with subclasses, but that isn't necessary. You can have several elements with the same class, one for each type of medium. There is nothing to implicitly define the filtering as in interpreting "book" as "media whose type is book", so you need to do the filtering in the code, probably in the (scripting) accessors for the different types of elements.

If you want to define different applescript types for the different types, to do things like "make new book", I don't think that's possible: different AS classes must be different Cocoa classes (I think). So if you'd want something like that you'd have to make the different types also different Cocoa classes.

Also, when you have a fixed number of types, I would use an enumeration for the type rather than a string. It's clearer, prevents abuse and mistyping, and mentions the possible values automatically in the scripting dict. 

HTH,
Christiaan

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-implementors mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >AppleScript-Cocoa Impedance Mismatch (From: Major Domo <email@hidden>)



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

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.