jl303 jl303 - 5 months ago 40
AppleScript Question

Applescript Filtering Arrays using whose ObjectSpecifier using Javascript

`The Javascript Automation release note by Apple has an example for searching an array with arbitrary objectSpecifier.

firstTabsName = ObjectSpecifier.tabs[0].name
app.windows.whose({_match: [firstTabsName, 'Apple']})

However, the first lines throws an error. "TypeError: undefined is not an object (evaluating 'ObjectSpecifier.tabs')
What am I doing wrong? Thank you for your help!`


The first line blows up at firstTabsName = ObjectSpecifier.tabs, which returns missing value. Nothing past that point can succeed.

The code you posted appears to be from the Apple Release Notes, which is missing an empty set of parens right after "ObjectSpecifier" and another set after the whose statement. When you add those parens, the constructor for ObjectSpecifier is called AND the final whose specifier is resolved to a list of matching windows. So, the corrected code is:

app = Application('Safari')
firstTabsName = ObjectSpecifier().tabs[0].name // added parens
app.windows.whose({_match: [firstTabsName, "Apple"]})() // added parens
// --> [Application("Safari").windows.byId(9016)]