Got nothing when I tried other places, so I thought I’d try here, since I know there are developers intimate with AppleScript around here.
I’ve been adding AppleScript support to my app. Returning some objects to a script shows them as the wrong class. Like here’s the AppleEvent when I request “keyword 1 of document 1”:
<NSAppleEventDescriptor: 'core'\'getd'{ '----':'obj '{ 'form':'indx', 'want':'Keyw', 'seld':1, 'from':'obj '{ 'form':'indx', 'want':'docu', 'seld':1, 'from':null() } }, &'csig':65536 }>
Looks good. Now here’s the object specifier as seen in my app’s log when I have NSScriptingDebugLogLevel set to 1:
Result: <NSAppleEventDescriptor: 'obj '{ 'from':'obj '{ 'from':null(), 'want':'docu', 'form':'name', 'seld':'utxt'("_Untitled") }, 'want':', 'form':'name', 'seld':'utxt'(" test picts 2") }>
Notice the malformed value for the 2nd ‘want’. It should be ‘want’:‘Keyw’, but it’s ‘want’:’
Looking at the returned object in Script Debugger shows the same thing when I view as AEPrint:
'obj '{ 'form':'name', 'want':', 'seld':'utxt'(" test picts 2"), 'from':'obj '{ 'form':'name', 'want':'docu', 'seld':'utxt'("_Untitled"), 'from':[0x0,104003f "Image Chest"] } }
And viewed as Best shows:
asset "test picts 2" of document "_Untitled"
The class should be “keyword” not “asset”. Why is AppleScript being annoying? Here are the relevant hunks of code and sdef:
@implementation Keyword (NSScriptObjectSpecifiers)
-(NSScriptObjectSpecifier*) objectSpecifier
{
Document* doc = self.doc;
return [[NSNameSpecifier alloc] initWithContainerClassDescription:(NSScriptClassDescription*)doc.classDescription containerSpecifier:doc.objectSpecifier key:@"scriptableKeywords" name:self.scriptableName];
}
@end
@interface Document
@property (readonly) NSArray<Asset*>* scriptableAssets;
@property (readonly) NSArray<Keyword*>* scriptableKeywords;
@property NSArray<Asset*>* scriptableSelection;
@end
@interface Keyword
@property (readonly) NSString* scriptableName;
@end
Relevant portion of .sdef:
<class name="asset" code="Asse" description="An asset being cataloged by the document.">
<cocoa class="Asset" />
</class>
<class-extension extends="document" description="A chest document.">
<cocoa class="Document" />
<property name="selection" code="sele" description="The selected assets.">
<cocoa key="scriptableSelection" />
<type type="asset" list="yes" />
</property>
<element type="asset" description="The assets being cataloged by the document.">
<cocoa key="scriptableAssets" />
<accessor style="index" />
<accessor style="id" />
<accessor style="test" />
</element>
<element type="keyword" description="The keywords known by the document.">
<cocoa key="scriptableKeywords" />
<accessor style="index" />
<accessor style="name" />
<accessor style="test" />
</element>
</class-extension>
<class name="keyword" code="Keyw" description="A keyword used with assets.">
<cocoa class="Keyword" />
<property name="name" code="pnam">
<cocoa key="scriptableName" />
<type type="text" />
</class>