I'm trying to add some scripting functionality to a Cocoa app that I've written. I've created an sdef (Scripting Definition File) for my project. So far I have been successful in accessing object children (elements) with AppleScript but I cannot for the life of me figure out how to call methods (commands).
Here is my sdef file.
<suite name="mySuite" code="mSUI" description="My Application Suite">
<class name="application" code="capp" description="Top level scripting object.">
<cocoa class="NSApplication"/>
<!-- I can access these elements fine -->
<element description="Test children." type="child" access="r">
<cocoa key="myChildren"/>
</element>
<!-- Cannot seem to call this method :( -->
<responds-to command="testmethod">
<cocoa method="exposedMethod:"/>
</responds-to>
</class>
<class name="child" code="cHIL" description="A Child." plural="children">
<cocoa class="Child"/>
<property name="name" code="pnam" description="The child name." type="text" access="r">
<cocoa key="name"/>
</property>
</class>
<command name="testmethod" code="tEST" description="Execute the test method" />
</suite>
Here are my controller class implementations (this is the delegate of my application)
MyController.h
#import <Cocoa/Cocoa.h>
@interface MyController : NSObject {
NSMutableArray* myChildren;
}
// Some Methods
@end
MyController+Scripting.m
#import "MyController+Scripting.h"
@implementation MyController (Scripting)
// This works when I'm accessing the myChildren
- (BOOL)application:(NSApplication*)sender delegateHandlesKey:(NSString*)key {
NSLog(@"Key = %@", key);
return ([key isEqualToString:@"myChildren"]);
}
// This does NOT work...
- (void)exposedMethod:(NSScriptCommand*)command {
NSLog(@"Invoked Test Script Method %@", [command description]);
}
@end
Lastly, the AppleScript I am trying is:
tell application "MyApplication"
testmethod
end tell
which responds with "AppleScript Error - The variable testmethod is not defined."
Any ideas what I'm doing wrong here? I feel like I'm missing something simple but my Googling doesn't seem to be turning up anything helpful.