Question

I've written the below code in vba to change comments in iTunes tracks in a Windows environment:

 Dim iTunes As New iTunesApp
 Dim library As IITLibraryPlaylist
 Dim tracksByArtist As IITTrackCollection
 Dim xSearch As String, xComment As String
 Dim track As IITFileOrCDTrack
 Dim i As Long, j As Integer

 Set library = iTunes.LibraryPlaylist
 xComment = "myComment"

 For i = 1 To NumberOfSongInItunes 'Number of songs in library
      If xArray(9, i) = "Target" Then 'xArray holds information that i've previously read from the library or xml file
           xSearch = "Artist Name " & "Album " & "Track Name"
           Set tracksByArtist = library.Search(xSearch, 0)

           For Each track In tracksByArtist
                track.Comment = xComment
           Next 
     End If
 Next

 Set iTunes = Nothing

I've been playing around in Xcode with ITLibrary, ITLibAlbum, ITLibArtist, etc. but with no success. Any ideas? Preferably not using applescript as it would be slow.

Was it helpful?

Solution

I'm not sure how well this fits in with what you're looking for, but the Scripting Bridge framework is always and option. The example below just changes the comment on which ever track is currently playing, but you can use iTunes.h and Scripting Bridge to do basically what ever you want with iTunes and its tracks.

#import <ScriptingBridge/ScriptingBridge.h>
#import "iTunes.h"


iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
[[iTunes currentTrack] setComment:@"I just added this cool comment to the current track!"];

There are recently generated copies of some of the Scripting Bridge headers on github, but I recommend that you compile your own to make sure everything is up to date. Instructions can be found here https://developer.apple.com/library/mac/DOCUMENTATION/Cocoa/Conceptual/ScriptingBridgeConcepts/Introduction/Introduction.html

Basically, to generate iTunes.h you'll need to run the following command.

sdef /Applications/iTunes.app | sdp -fh --basename iTunes

OTHER TIPS

there is no public API for that. you would have to open the XML file and edit it. It is prone to break though

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top