在MacOS上更改iTunes Track评论

时间:2014-01-27 11:35:40

标签: macos itunes

我在vba中编写了以下代码,以便在Windows环境中更改iTunes曲目中的注释:

 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

我一直在使用ITLibrary,ITLibAlbum,ITLibArtist等在Xcode中玩,但没有成功。有任何想法吗?最好不要使用AppleScript,因为它会很慢。

2 个答案:

答案 0 :(得分:0)

没有公共API。您必须打开XML文件并进行编辑。它很容易破裂

答案 1 :(得分:0)

我不确定这与你正在寻找什么相符,但是Scripting Bridge框架总是可行的。下面的示例只是更改了当前正在播放的曲目的注释,但您可以使用iTunes.h和Scripting Bridge基本上按照iTunes及其曲目进行操作。

#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!"];

最近生成了一些Scripting Bridge标头on github的副本,但我建议您编译自己的副本以确保所有内容都是最新的。可以在https://developer.apple.com/library/mac/DOCUMENTATION/Cocoa/Conceptual/ScriptingBridgeConcepts/Introduction/Introduction.html

找到相关说明

基本上,要生成iTunes.h,您需要运行以下命令。

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