Here’s a sample script typed in Script Editor: tellapplication “Finder” toreturn bounds offinder 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.
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.
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…