这是您要查找的脚本。我留下第一个答案,因为它也可能对其他人有用。
property RList : "my random list" -- name of the random list
property ListGenres : {"Rock", "Pop", "Soundtrack", "Jazz"} -- your list of genres
property NumPerGenre : {3, 2, 5, 4} -- the number of songs per genre
tell application "iTunes"
if exists user playlist RList then -- check if the playlsit exists or not
delete tracks of user playlist RList -- delete all current tracks of the play list
repeat while (number of tracks of playlist RList) > 0
delay 0.1 -- wait for the library to clear out, because iTunes is asynchronous !
end repeat
else -- creation of the play list
set MyPlayList to make new user playlist with properties {name:RList}
end if
repeat with I from 1 to (count of ListGenres) -- loop per genre
set ListTracks to (tracks whose genre is (item I of ListGenres))
repeat with J from 1 to (item I of NumPerGenre) -- loop to add x tracks per genre
set TheTrack to item (random number from 1 to (count of ListTracks)) of ListTracks
duplicate TheTrack to playlist RList
end repeat -- loop for all tracks per genre
end repeat -- loop by Genre
play playlist RList -- start to play !
end tell
我已经发表了很多评论来说明清楚(我希望)。在这个例子中,我有 4 个流派,我会得到第一个流派的 3 首歌曲,第二个流派的 2 首歌曲,……以此类推。您可以更改这些属性,只要流派列表的项目数与 numpergenre 列表相同。
不幸的是,由于iTunes 11,shuffle属性无法通过脚本设置,必须在iTunes中手动设置才能随机播放列表(可以设置一次)