You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过iTunes脚本向xMusic播放列表添加无重复歌曲?

从源头避免重复添加歌曲到xMusic播放列表的AppleScript方案

完全可以实现!你的思路踩对了方向——咱们直接在筛选待添加歌曲的环节,就把已经存在于目标xMusic播放列表里的歌曲排除掉,从根源杜绝重复,不用再事后跑删除脚本。

下面是针对你需求的具体AppleScript示例,我会拆解关键部分帮你理解:

tell application "iTunes"
    -- 先定义你的目标xMusic播放列表,把名称改成你实际使用的那个
    set targetPlaylist to playlist "xMusic 我的专属列表"
    
    -- 筛选符合条件的歌曲:genre是Rock,且不在目标播放列表里
    set songsToAdd to every song in playlist "Music" whose genre is "Rock" and it is not in targetPlaylist
    
    -- 如果找到符合条件的歌曲,就添加到目标列表
    if length of songsToAdd > 0 then
        add songsToAdd to targetPlaylist
        display dialog "成功添加 " & (length of songsToAdd) & " 首无重复的摇滚歌曲!"
    else
        display dialog "没有符合条件的新歌曲可以添加~"
    end if
end tell

关键逻辑说明

  • 核心筛选条件:whose genre is "Rock" and it is not in targetPlaylist——这里的it指代当前遍历的歌曲,直接用not in targetPlaylist判断歌曲是否已在目标列表里,比单独对比名称更准确(毕竟可能存在同名但不同版本/艺术家的歌曲)。
  • 灵活调整筛选维度:如果想更严格地避免重复(比如同一首歌的不同版本也不想添加),可以拓展条件,同时对比名称和艺术家:
    set songsToAdd to every song in playlist "Music" whose genre is "Rock" and ¬
        name is not in (name of tracks of targetPlaylist) and ¬
        artist is not in (artist of tracks of targetPlaylist)
    
  • 播放列表名称注意:一定要把"xMusic 我的专属列表"改成你实际使用的xMusic播放列表的准确名称,不然脚本会找不到目标列表。

小提示

  • 你可以把这个脚本保存成.scpt文件,每次需要添加对应genre的歌曲时直接运行就行;
  • 如果经常需要切换不同genre,还可以把genre做成变量,比如开头加set targetGenre to "Rock",后面直接引用targetGenre,修改起来更省心。

内容的提问来源于stack exchange,提问作者tardy pigeon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:43:52