Cocoa Scripting: Getting the index of a scriptable object in its container

174 views Asked by At

Given a scriptable object's NSScriptObjectSpecifier, how do I tell the index of object(s) in their container?

I cannot find any accessor method for that in the NSScriptObjectSpecifier or its subclasses.

If the object is a NSIndexSpecifier, it's easy to get the index. But if it's something else, e.g. a NSNameSpecifier, then it needs to be inquired. The Cocoa Scripting guide says that the framework does that automatically when it needs to learn the index, but it's not explained how that's done.

There is the method indicesOfObjectsByEvaluatingObjectSpecifier a scriptable object can implement to return such indices, but that's an optional method, and so I assume I cannot simply invoke that on any scriptable object.

Is there some other easy way to learn the index, or do I have to implement my own method that walks down the specifiers and handles all the possible cases on its own?

1

There are 1 answers

0
Ron Reuter On

Are you looking for NSArray's

- indexOfObjectIdenticalTo:self

by any chance? I use this in an -objectSpecifier method when I need to return a formIndex ospec.