Using Whose Arrays in Javascript to Automate

Play with the new JS for automation using the Script editor. I get an error in the last line:

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

It is confirmed that the array of sources was as expected (two elements, one with name"Library" and one "Internet Radio"). But this final line is throttled 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 correct syntax for the functionwhose . (I also tried with an explicit sentence _equalsto the same result.) What am I doing wrong?

+4
source share
4 answers

, .

(function () {
    'use strict';

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

    return filtered().length;

})();
+2

?

: . JXA - .

: . " " , source library .

, ; Finder :

items of folder "Desktop" of folder "jsmith" of folder "Users" of disk "Macintosh HD" of app "Finder"
items of folder "Desktop" of folder "jsmith" of folder "Users" of startup disk of app "Finder"
items of folder "Desktop" of home of app "Finder"
items of folder "Macintosh HD:Users:jsmith:Desktop" of app "Finder"
items of desktop of app "Finder"
items of app "Finder"
[etc.]

Apple . , : , .

...

iTunes () (ObjectSpecifiers), source iTunes:

var iTunes = Application("iTunes");
var sources = iTunes.sources();

, , JavaScript , . , , :

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

, source, "". ( source "", byName whose, .)

-

, , JXA Apple, , Lame Fail . , . " ", , - AppleScript: , .

( AppleScript/JXA : JavaScriptOSA , , , . pisiness, .)

+6

JavaScript Mail.inbox.messages.whose(...) :

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

" whose" ", ", ( ) OS X JavaScript.

, whose JXA, , OS X v.10.10.

, (.. 2 ), JavaScript JS.

1

var iTunes = Application('iTunes');
var sources = iTunes.sources();
var librarySource = null;
for (key in sources) {
    var name = sources[key].name();
    if (name.localeCompare("Library") == 0) {
        librarySource = sources[key];
    }
}

2

var iTunes = Application('iTunes');
var sources = iTunes.sources();
function hasLibraryName(obj) {
    var name = obj.name();
    if (name.localeCompare("Library") == 0) {
        return true;
    }
    return false;
}
var filtered = sources.filter(hasLibraryName); 
0

OS X 10.11.5 .

library = Application("iTunes").sources.whose({name:'Library'})()[0]

library.properties()

// {"class":"source", "id":64, "index":1, "name":"Library", "persistentID":"2D8F973150E0A3AD", "kind":"library", "capacity":0, "freeSpace":0}

() who, , [0], ( ) , .

"" , , , :

library = Application("iTunes").sources.whose({kind:"kLib"})()[0]
0

All Articles