I want to make my app scriptable and am running into a few issues I hope some of you may help me with since my experience with making apps scriptable is not great.
The app is not document-based and has a several global named objects of the same class that I want to be accessed from AppleScript. For example, say that I want to have a several catalogues, each named, say "animals", "plants", "cars". I have managed to add several properties to the application class (in AppleScript), each representing one of the catalogues:
<class name="application" description="My application." code="capp" inherits="application">
<cocoa class="NSApplication"/>
<property name="animals catalogue" code="acat" description="…" type="catalogue" access="r">
<cocoa key="animalsCatalogue"/>
</property>
<property name="cars catalogue" code="ccat" description="…" type="catalogue" access="r">
<cocoa key="carsCatalogue"/>
</property>
<property name="plants catalogue" code="pcat" description="…" type="catalogue" access="r">
<cocoa key="plantsCatalogue"/>
</property>
</class>
I am able to successfully fetch any of those variables, e.g.
tell application "MyApp"
set c to get animals catalogue
end tell
gets me really the catalogue variable («class ����» "Animals" of application "MyApp"
).
Unfortunately, where it gets tricky is when it comes to getting a property from the catalogue - for example 'empty'. Here is the catalogue definition:
<class name="catalogue" code="ctlg" description="...">
<cocoa class="XYCatalogue"/>
<property name="empty" code="empt" description="Is the catalogue empty?" type="boolean" access="r">
<cocoa key="isEmpty"/>
</property>
</class>
The issue here is that when running this AppleScript:
tell application "MyApp"
set c to get animals catalogue
get empty of c
end tell
results in an error: MyApp got an error: Can’t make «class ����» "Animals" into type specifier.
Implementation-wise, I have the NSApplication subclassed (and yes, I have specified the main class in Info.plist), which implements several methods, returning those particular catalogues. The XYCatalogue
class implements the -objectSpecifier
method this way:
return [[[NSNameSpecifier alloc] initWithContainerClassDescription:
[NSScriptClassDescription classDescriptionForClass:[NSApp class]]
containerSpecifier:nil
key:@"allCatalogues"
name:[self name]] autorelease];
The NSApplication subclass implements a -allCatalogues
method that returns all the catalogues. I have tried even using the NSUniqueIDSpecifier
and the NSPropertySpecifier
, all in vain. And yes, the NSApplication subclass does implement both -valueWithName:inPropertyWithKey:
and -valueInAllCataloguesWithName:
methods and neither is invoked (have breakpoints in both of them).
I have sincerely read Apple's guide several times, however, still can't figure out where is the issue and I'm hanging on this for a few days now. I would be most thankful for any nudge in the right direction. Thanks!