Saturday, 17 August 2013

How to implement an AppleScript element (a "one-to-many" relation) of the application class?

How to implement an AppleScript element (a "one-to-many" relation) of the
application class?

Here's what I have:
1) Include the proper "permissions" entries in the 'Info.plist
'Scriptable': YES
'Scripting definition file name': myApp.sdef
2) Include the element "element" tag within a class extension "element" tag:
`<class-extension extends="application" description="The application and
top-level scripting object.">
<!-- various property tags go here -->
<element type="object item" access="r">
<cocoa key="theseObjects"/>
</element>
</class-extension>`
3) Include the element class tag:
<class name="object item" code="Objs" description="Application 'too many'
object collection" plural="object items" inherits="item"> // I don't
believe 'inherits' name is critical for AS to work
<cocoa class="ObjectItem"/>
</class>
4) Include the delegate method that forwards 'NSApplication' scriptability
support to its delegate:
- (BOOL)application:(NSApplication *)sender delegateHandlesKey:(NSString
*)key {
if ([key isEqualToString:@"theseObjects"]) {
return YES;
}
return NO;
}
5) Create a 'ObjectItem' class that includes an 'objectSpecifier' that
establishes the application as the container class:
- (NSScriptObjectSpecifier *)objectSpecifier {
NSScriptObjectSpecifier *containerRef = nil;
NSScriptObjectSpecifier *specifier = [[NSNameSpecifier alloc]
initWithContainerClassDescription:[NSScriptClassDescription
classDescriptionForClass:[NSApp class]] containerSpecifier:containerRef
key:@"theseObjects" name:@"objects"];
return [specifier autorelease];
}
6) Post the KVO accessor method within the Application's delegate:
- (NSArray *)theseObjects;
{
ObjectItem *thisObject = [[ObjectItem new] autorelease];
NSArray *thisArray = [NSArray arrayWithObject:thisObject];
return thisArray;
}
7) Create an AppleScript that returns objects from my element getter method:
tell application "SpellAnalysis"
get theseObjects
end tell
8) The result: error "The variable objects is not defined." number -2753
from "objects"
9) Pull my hair out

No comments:

Post a Comment