jl303

Q: Applescript Iterate UIElements using Javascript

Could someone please help me to make a script that reports all the children and its properties of an uielement? It's similar to entireContents() function. Here's my recursive function.

function iterate(obj) {

for (var property in obj) {

if(obj[property] instanceof Array) {

console.log("Array: " + property + "," +obj[property])

iterate(obj[property])

} else if(obj[property] instanceof Object){

console.log("Object: " + property + ',' + obj[property])

iterate(obj[property])

} else {

console.log("Unknown: " + property +"," + obj[property]);

}

}

}

 

iterate(app.windows())

I only get the first level. There are bunch of UIElements and arrays under each item.

I think it has to do with Applescript returning object specifier, but not actual object? I'm not sure how to invoke name of the object specifier as function.

I tried obj[property](), obj.property(), eval("obj." + property + "()"), ,and none of them works.

I also tried iterate(app.windows())[0]

Thank you for your help.

iMac with Retina 5K display, OS X El Capitan (10.11.4)

Posted on Jul 5, 2016 2:50 PM