如何使用Applescript搜索iTunes?

时间:2009-12-28 21:31:15

标签: applescript

如何搜索符合特定条件的每首歌曲?例如:

tell application "iTunes"
    set tracks to (every file track of playlist "Library" whose name contains "Green")
    repeat with t in tracks
        display dialog (t as string)
    end repeat
end tell

1 个答案:

答案 0 :(得分:4)

就像那样,除了两件事;首先,tracks是iTunes脚本词典中的保留字,因此将其替换为其他内容(例如 ts);第二,你不能只用t as string将曲目​​转换为字符串;你必须选择你想要的信息。例如,如果您想要名称,可以使用name of t as string;如果你想要更多细节,你可以做name of t & " - " & artist of t;另请注意,如果您想要更复杂的谓词,可以将其添加到whose子句中;例如,file tracks whose name contains "Green" and artist contains "Bird"

如果您想稍微打高级脚本,可以使用以下内容替换它:

tell application "iTunes"
    repeat with t in (file tracks whose name contains "Green")
        display dialog (name of t as string)
    end repeat
end tell

删除of playlist "Library"可能会产生稍微不同的结果,但可能不会。它没有在我的快速测试中。