如何使用Applescript计算iTunes中的选中项目

时间:2013-03-06 11:43:33

标签: applescript itunes

我正在尝试创建一个小脚本,其中包含所选项目的列表,并计算每个所选项目出现在库中其他位置的次数。如果有重复项,则会关闭复选标记,如果这是唯一的副本,则会将其打开。

这很有效。

但我想做的是让它只检查已检查歌曲的库。但是当我在末尾(第三行set行)添加“enabled”位时,脚本会超时。

repeat with entry in selection -- "selection" is a concept implemented in iTunes 
    set a to artist of entry
    set n to name of entry
    set x to count of (file tracks whose name contains n and artist contains a and enabled is true)
    ...
    display dialog x
end repeat

如果我取出and enabled is true它会按预期快速完成,并且结果符合预期。

在行尾有and enabled is true,发生了一些神秘的事情。显然我检错了

1 个答案:

答案 0 :(得分:1)

以下是一个快速解决方法:

tell application "iTunes"
    repeat with entry in selection -- "selection" is a concept implemented in iTunes 
        set a to artist of entry
        set n to name of entry
        set myTracks to (file tracks whose name contains n and artist contains a)
        set x to {}
        repeat with aTrack in myTracks
            if aTrack's enabled = true then set end of x to aTrack
        end repeat
        display dialog (count x)
    end repeat
end tell