我正在尝试将我的 iTunes 中的所有歌曲名称写入 txt 文档。我遇到的第一个问题是我似乎无法正确循环操作。这是我的 iTunes 中前 15 首歌曲的测试用例:
tell application "TextEdit"
make new document
end tell
tell application "iTunes"
set trNameID1 to name of track 1
set trNameID2 to name of track 2
set trNameID3 to name of track 3
set trNameID4 to name of track 4
set trNameID5 to name of track 5
set trNameID6 to name of track 6
set trNameID7 to name of track 7
set trNameID8 to name of track 8
set trNameID9 to name of track 9
set trNameID10 to name of track 10
set trNameID11 to name of track 11
set trNameID12 to name of track 12
set trNameID13 to name of track 13
set trNameID14 to name of track 14
set trNameID15 to name of track 15
tell application "TextEdit"
set text of document 1 to {trNameID1 & "
", trNameID2 & "
", trNameID3 & "
", trNameID4 & "
", trNameID5 & "
", trNameID6 & "
", trNameID7 & "
", trNameID8 & "
", trNameID9 & "
", trNameID10 & "
", trNameID11 & "
", trNameID12 & "
", trNameID13 & "
", trNameID14 & "
", trNameID15} as text
end tell
end tell
当我尝试循环播放时,txt 文档只包含最后一首歌的名称,例如:
tell application "TextEdit"
make new document
end tell
tell application "iTunes"
set trNum to 1
repeat 15 times
set trNameID to name of track (trNum)
tell application "TextEdit"
set text of document 1 to trNameID & "
"
end tell
end repeat
end tell
这只会将第十五首歌曲的名称输出到 txt 文档中。
我意识到这可能是非常基本的,但我实际上已经使用 applescript 大约 48 小时,我似乎无法弄清楚这一点。我希望所有歌曲名称都在一个 txt 文档中,这样我就可以阅读和分析 C++ 中的字符串。有没有人有任何想法?
另外,我不确定在 AppleScript 中是否有办法查看整个 iTunes 库并查看最后一首歌曲,在 iTunes 中记录该歌曲的 id,然后重复循环通过该 id。这样,循环将完全适用于库中的歌曲数量。
任何想法将不胜感激!