Search code examples
javascriptcomitunes

Accessing newly added tracks in iTunes with COM interface


I am trying to add track information to newly added tracks in iTunes using the COM interface and JavaScript. I am able to successfully add files, but am unable to grab them using OperationStatus.Tracks(). I know that OperationStatus.Tracks() is unavailable until after OperationStatus.InProgress() returns false. However, when I try to call InProgress() on what I expect to be an OperationStatus object, I receive the error: "Object doesn't support this property or method."

var iTunesApp = WScript.CreateObject("iTunes.Application");
var status = iTunesApp.LibraryPlaylist.AddFile('newfile.mp4');
WScript.Echo(status.InProgress());

Can anyone shed some light on to what is going wrong here?


Solution

  • I have since been able to answer my own question. I was simply adding empty parens when no parameters were necessary. As such, the methods and properties were not being recognized. The last line mentioned above will work in the following form:
    WScript.Echo(status.InProgress);

    To access the tracks that have been recently added can be done using
    var newtracks = status.Tracks;

    Then to access properties about an individual track can be done as follows:
    var newtrack = newtracks.ItemByName('filename');
    WScript.Echo(newtrack.Name);