我有一个 iTunes 播放列表,我之前已备份到一个文本文件中,格式如下:
“标题”、“艺术家”、“曲目编号”、“专辑”
我使用其中四个轨道创建了一个示例文件:
"Ritual","Chick Corea Elektric Band II","9","Paint The World"
,"Risk","Deftones","9","Diamond Eyes"
,"Risveglio","Goblin","10"," Zombi"
"Ritual","Ashes Divide","8","一直告诉自己没关系"
此播放列表中的所有曲目当前都在 iTunes 中。我想使用 AppleScript 将这些曲目中的每一个添加到播放列表中。我已经能够使用以下 AppleScript 使用单个项目(例如:标题)来做到这一点:
-- set variables
set srcFile to "/Users/kjesso/Documents/=Scripting=/AppleScript/ipod_gym_playlist_track_names_sample.txt"
set allRecords to paragraphs of (read srcFile as «class utf8»)
set myPlaylist to "Test"
property okflag : false
-- check if iTunes is running
tell application "Finder"
if (get name of every process) contains "iTunes" then ¬
set okflag to true
end tell
if okflag then
-- if iTunes is running then do this
tell application "iTunes"
repeat with aRecord in allRecords
set results to (every file track of playlist "Library" whose name is aRecord)
repeat with aTrack in results
duplicate aTrack to playlist myPlaylist
end repeat
end repeat
end tell
else
-- if iTunes is not running do this
return "Unable to execute because iTunes is not running"
end if
但是,如果从不同的艺术家那里找到重复的曲目标题,它将只使用第一首曲目,因为脚本无法区分仅以“标题”作为内容的不同艺术家。AppleScript 中是否存在数组?
我认为这需要使用属性列表文件来完成?在网上进一步阅读后,尝试创建一个数组来做我想做的事情(捕获曲目标题、艺术家、专辑等),我遇到了各种类似这样的线程,说明最好使用属性列表?我正在尝试实现与此处所做的类似,但不是将输出发送到 CSV 文件,而是将其发送到 iTunes 中的播放列表。
如果我需要使用属性列表来实现我的目标,我创建了以下示例属性列表文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>title</key>
<string>"Ritual"</string>
<key>artist</key>
<string>"Chick Corea Elektric Band II"</string>
<key>album</key>
<string>"Paint The World"</string>
</dict>
<dict>
<key>title</key>
<string>"Risk"</string>
<key>artist</key>
<string>"Deftones"</string>
<key>album</key>
<string>"Diamond Eyes"</string>
</dict>
<dict>
<key>title</key>
<string>"Risveglio"</string>
<key>artist</key>
<string>"Goblin"</string>
<key>album</key>
<string>"Zombi"</string>
</dict>
<dict>
<key>title</key>
<string>"Ritual"</string>
<key>artist</key>
<string>"Ashes Divide"</string>
<key>album</key>
<string>"Keep Telling Myself It's Alright"</string>
</dict>
</plist>
任何人都对如何让它发挥作用有任何想法?