Trouble implementing selection property

Steve Mills

I'm not sure what I'm doing wrong when adding a "selection" property to my document class so the user can get and set the selected assets. When I run:

tell application "Image Chest"
tell document 1
set blah to selection
set selection to blah
—>Can’t make asset 76 of document "_Untitled" into type specifier.
end tell
end tell

I've tried using both NSIndexSpecifier and NSUniqueIDSpecifier when returning the objectSpecifier for the Asset class, and they work if I do something simple like:

set blah to asset 1 of document 1
return name of blah

The selection property is structured in the sdef as:

<property name="selection" code="seld" description="The selected assets.">
<type type="asset" list="yes" />
<cocoa key="scriptableSelection" />

Do I need to override some method in some class, like indicesOfObjectsByEvaluatingObjectSpecifier:? I tried adding one of those to the Document class so I could inspect all the incoming specifiers, then returned nil so the default implementation would do the evaluation instead. It never gets called when the "set selection to blah" line is being run.

It's been a long time since I've done any serious AppleScript implementation, and that was in a huge Carbon app. So maybe I'm trying to do something that's impossible? Maybe I instead need to add a "select" verb?

Steve Mills
Drummer, Mac geek

Steve Mills

It turns out that if you dink around enough, sooner or later things just work right. Maybe AppleScript was keeping a cached version of my dict in memory or something, but I quit Script Debugger and cleaned & built my app many times. Then suddenly it worked.

But now I'm getting this problem. 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?

Steve Mills
Drummer, Mac geek