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

时间:2015-08-04 23:13:37

标签: applescript itunes

以下是我正在尝试使用的实际代码:
if(tvshow文件夹中有多集,且至少有一集被标记为未观看){ 删除观看的剧集 }

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

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

1 个答案:

答案 0 :(得分:0)

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

由于您的请求有点含糊不清

  

...至少有一集被标记为无人看管
     和
   ...一集...即使该节目被标记为观看或未观看

如果至少有一个未观看过的剧集,该剧本将删除播放列表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