AppleScript implementation: Wrong class is displayed

I've been adding AppleScript support to my app. Didn't get any responses on cocoa@apple-dev.groups.io, and applescript-implementors is dead, so I'll try here.


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?

Replies

Why is AppleScript being annoying?


All code is annoying when it does not work as wished…


Now, to move forward, could you post the related code ?

It's annoying because it's doing the wrong thing when it should be a cakewalk.


There's not much code to post:


@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


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 (readonly) NSString* scriptableName;

</class>

Nobody?