fileselectitunesscripting-bridge

get a specific track in itunes via ScriptingBridge


I'm updating my OS X program to accept iTunes drops, modify the metadata in the file, then refresh (Get Info) the dropped file(s) so iTunes can update its' metadata library.

I've got the drops working, which provide a dictionary of some misc info about the file including track ID, persistent ID, and Location. I'm at the point now where I need to get a specific track, either by file location or the persistant ID provided by the drop info, so I can call the refresh method on it to force iTunes to reexamine the file and update the changes to the metadata.

I've got the iTunes header file imported and the SBApplication object created, I'm pretty stuck at this point on an efficient way to get the proper track.


Solution

  • As stated, I already had access to some info about a file provided by an iTunes drop. I needed to match up info about that file based on either the file name or persistentID provided by the drop to the file in the iTunes library my solution was to use a predicate filter on the iTunes library against the library collection returned by the iTunes scripting bridge.

        iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
    
        SBElementArray *sources = [iTunes sources];
    
        SBElementArray *entireLibrary = [[[[sources objectAtIndex:0] libraryPlaylists] objectAtIndex:0] fileTracks];
    
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"persistentID == %@", persistentID];
    
        [entireLibrary filterUsingPredicate:predicate];