Applescript 从 iTunes 资料库中删除观看过的电视节目

Applescript to Delete Watched TV Shows from iTunes Library

以下是我尝试使用实际代码执行的操作:
如果(电视节目文件夹中有多个剧集,并且至少有一个剧集被标记为未观看){ 删除观看的剧集 }

我的目标是始终在 TVShow 文件夹中保留一集。即使该节目被标记为已观看或未观看。发生删除的唯一情况是有多集并且其中一集被标记为未观看。我需要这个脚本在 iTunes 中的所有电视节目中 运行。这将使我的 iTunes 帐户更小,并自动删除我观看的节目。有人知道怎么做吗?我对 Applescripting 很陌生。

顺便说一句,如果重要的话,我指的是那些我已经添加到 iTunes 商店之外的 iTunes 资料库中的电视节目。此脚本不会删除购买的电视节目。感谢您的帮助!

提供删除内容的脚本总是很危险的。

由于您的要求有点模棱两可

… at least one episode is marked as unwatched
and
… a single episode … even if that show is marked as watched or unwatched

脚本将删除播放列表中所有已观看的剧集 TV Shows 如果至少有一个未观看的剧集。
所有未观看的剧集都删除。

有两个脚本,一个用于测试,一个用于删除。


脚本 #1 不会删除任何内容,但会显示应该删除的项目列表。

tell application "iTunes"
    set watchedEpisodes to tracks of playlist "TV Shows" whose unplayed is false and played count > 0
    set unwatchedEpisodes to tracks of playlist "TV Shows" whose unplayed is true
    if (count unwatchedEpisodes) > 0 then
        set trackNames to {}
        repeat with anEpisode in watchedEpisodes
            set end of trackNames to ((name of anEpisode) as text) & " of show " & show of anEpisode
        end repeat

        set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
        display dialog trackNames as text
        set AppleScript's text item delimiters to TID
    end if
end tell

请仔细检查输出


脚本 #2 删除符合条件的项目

tell application "iTunes"
    set watchedEpisodes to tracks of playlist "TV Shows" whose unplayed is false and played count > 0
    set unwatchedEpisodes to tracks of playlist "TV Shows" whose unplayed is true

    if (count unwatchedEpisodes) > 0 then
        repeat with anEpisode in watchedEpisodes
            delete anEpisode
        end repeat
    end if
end tell