Confused about the AppleEvent's rectangle type and Xojo

Hi,

Here’s a sample script typed in Script Editor:
tell application “Finder” to return bounds of finder window 1

It gives me this result:
{0, 821, 423, 1356}

So far, so good.

I’m now trying the same thing in Xojo. This is my current code:

Var ae As new AppleEvent("core","getd","com.apple.finder") //Get

Var o1 As AppleEventObjectSpecifier=GetIndexedObjectDescriptor("brow",nil,1) //Finder window 1
Var o2 As AppleEventObjectSpecifier=GetPropertyObjectDescriptor(o1,"pbnd") //Bounds
ae.ObjectSpecifierParam("----")=o2

if ae.Send then
  //Reference point 1

  Var aedl As AppleEventDescList=ae.ReplyDescList

  //Reference point 2
  var Rec As AppleEventRecord=aedl.RecordItem(1)
    Break
end if

At “Reference point 1”, once the event was sent, the various Reply[…] properties are all null, except ReplyDescList, which contains a single item.
At “Reference point 2”, the content of the DescList’s single item is an AppleEventRecord (all other values of the DescList are null).

This is where my confusion arises. I’d expect an AppleScript’s bound (rectangle) to be an array of 4 integers, which would be a DescList rather than a Record. Some websites tend to agree with that.

A record, on the other hand, would contain 4 characters-named parameters, accessed like Value=Record.IntegerParam(“left”), but, assuming Xojo is right that it got a record, I can’t find a list of these parameters’ name to retrieve the bound’s values.

Any idea what’s going on?

I took a look at the Finder’s dictionary and I believe it is returning a QuickDraw Rect data structure. I believe I have code to handle this - I’ll look later when I have time.

Thank you.

I’m in the process of solving this problem on my side as well. I don’t know how it’s reliable, though.

I’m still assuming Xojo has a bug, because it gets a record instead of a DescList, but I’ve noticed another interessant thing: the ReplyString data isn’t empty (it’s the only non-empty one except ReplyDescList, but I didn’t pay attention to it until now).
It seems that applying that string to a MemoryBlock and then accessing Int16 values from it returns the correct values. My code looks like this:

Var ae As new AppleEvent("core","getd","com.apple.finder")

Var o1 As AppleEventObjectSpecifier=GetIndexedObjectDescriptor("brow",nil,WindowIndex) //Index from 1 to windows count
Var o2 As AppleEventObjectSpecifier=GetPropertyObjectDescriptor(o1,"pbnd")
ae.ObjectSpecifierParam("----")=o2

if ae.Send then
  Var m As new MemoryBlock(8)
  m=ae.ReplyString
  
  Return new Rect(m.Int16Value(2),m.Int16Value(0),m.Int16Value(6),m.Int16Value(4))
end if

But I find weird to convert a string to an array of integers like that…

Good job! That’s correct though. It’s a data structure and you need to treat it like that.

In fact, this is exactly where you should consider using a Xojo Structure. It will make your code more readable.

Thank you.