Ben Zotto Ben Zotto - 9 months ago 61
AppleScript Question

Using "whose" on arrays in Javascript for Automation

Playing with the new JS for automation using Script Editor. I'm getting an error on the final line of the following:

var iTunes = Application("iTunes");
var sources = iTunes.sources();
var library = sources.whose({name : "Library"});

Confirmed that the sources array is as expected (two elements, one with
"Library" and one "Internet Radio"). But that final line chokes with
Error on line 3: TypeError: undefined is not a function (evaluating 'sources.whose({name : "Library"})')

As far as I can tell, I'm using the right syntax for the
. (I also tried with an explicit
clause to the same result.) What am I doing wrong?


This now works as theory would predict.

(function () {
    'use strict';

    var iTunes = Application('iTunes'),
        filtered = iTunes.sources.whose({
            name: 'Library'

    return filtered().length;