【发布时间】:2016-09-11 06:13:21
【问题描述】:
我有一个 iTunes 播放列表,我之前已备份到一个文本文件中,该文件格式如下:
“标题”、“艺术家”、“曲目编号”、“专辑”
我使用其中四个轨道创建了一个示例文件:
“Ritual”、“Chick Corea Elektric Band II”、“9”、“Paint The World”
“风险”、“Deftones”、“9”、“钻石眼”
"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 中是否原生存在数组?
我认为这需要使用属性列表文件来完成?在网上进一步阅读后,尝试创建一个数组来做我想做的事情(捕获曲目标题、艺术家、专辑等),我遇到了各种线程like this 说最好使用属性列表?我正在尝试实现类似于 here 所做的工作,但我不想将输出发送到 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>
有人对如何让它工作有任何想法吗?
【问题讨论】:
标签: applescript itunes playlist property-list