1

In my scriptable app, one of the properties is of a named record type, and that record type has been declared in the sdef as well (named "custom record").

I can get the record like this:

get owner of anElement
    --> {pool:"test", position:2}

I can also successfully test for it like this:

set target to {pool:"test", position:2}
if owner of anElement = target then
    -- found!

But I cannot use it in a whose clause:

get allElements whose owner = target
    --> {}

I also cannot use missing value in the test:

get allElements whose owner = missing value
    --> error number -1700 from missing value to custom record

Is that expected behavior with AppleScript, i.e. is it unable to handle records in whose clauses?

Or am I doing something wrong? I have so far not implemented any coercion handlers nor special record handlers because nothing has indicated that I'd need them.

Also, please see my related question: Cocoa Scripting: Returning "null" vs. "missing value"

Community
  • 1
  • 1
Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149

1 Answers1

2

Short answer : It's expected behavior.

The whose clause works only for element reference types (classes which have an object specifier), but not for record types and custom lists.

Even the selection property of the Finder cannot be filtered by a whose clause.

vadian
  • 274,689
  • 30
  • 353
  • 361
  • Ah, *only classes which have an object specifier* makes sense. I'll consider turning the record into individual properties then to make this easier to handle. It's only two items in the record. I thought using a record type would make it look cleaner in the dictionary, but that's not really necessary. – Thomas Tempelmann Apr 29 '16 at 09:48
  • 1
    Actually OP's AS code should work, since he's applying a query to a one-to-many relationship (`allElements whose TEST`), not an array of records. The inability to do an equality test on a property containing a record is most likely due to Cocoa Scripting being a bit shoddy and failing to perform the `owner = {pool:"test", position:2}` test correctly. As to `missing value` failing, OP should check his SDEF includes `` in the property's type declaration. – foo Apr 29 '16 at 10:01
  • @foo whose clause doesn't work for record types due to the lack of an `NSScriptObjectSpecifier`. It's a fact. – vadian Apr 29 '16 at 10:12
  • @foo - On the "missing value" type. If I add that, with code "msng", it's still not working. I get the error "Can’t make missing value into type custom record." number -1700" – Thomas Tempelmann Apr 29 '16 at 10:25
  • Also, please see my related question about null and "missing value": http://stackoverflow.com/questions/36921259 – Thomas Tempelmann Apr 29 '16 at 10:40
  • 1
    See `man 5 sdef`; the `owner` property should be defined as ``. – foo Apr 29 '16 at 10:51
  • @foo, are you saying I can include TWO types in a single property declaration? The Sdef editor won't let me do that, BTW. Thanks for the pointer to the `man` for sdef - I had no idea that exists. – Thomas Tempelmann May 07 '16 at 18:12
  • @foo - indeed, the man page says that I may use multiple types in a single element. That will prevent me from using the Sdef editor as it'll remove anything from the sdef it doesn't understand next time I save. But it's a step forward. – Thomas Tempelmann May 07 '16 at 18:33