Using “whose” on arrays in Javascript for Automation

前端 未结 4 1124
攒了一身酷
攒了一身酷 2021-02-10 12:40

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 s         


        
4条回答
  •  被撕碎了的回忆
    2021-02-10 13:21

    In OS X 10.11.5 this seems to be working just fine.

    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}
    

    Note the addition of () after the whose clause to resolve the object specifier into an array of references and then the [0] to get the first (and only, in my case) library object reference, which can then be used to get the properties of that library.

    In case the source is not named "Library" in other languages or regions, I would probably use this instead:

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

提交回复
热议问题