根据制表符分隔的列表从iTunes播放列表中删除歌曲

时间:2018-09-22 20:25:10

标签: applescript itunes

如果使用包含在制表符分隔文件中的名称+艺术家+年份之一,我如何使用Applescript从myPlaylist中删除任何歌曲?

因此,如果跟踪myPlaylist之一是:

'Greensleeves The Scorpions 1965'

,并且制表符分隔的文本文件包含以下行:

Greensleeves The Scorpions 1965

它将从播放列表中删除曲目。另外,它必须是准确的标题,因为我的某些歌曲标题中带有方括号和奇数字符。

谢谢!

1 个答案:

答案 0 :(得分:2)

use application "iTunes"
use scripting additions
--------------------------------------------------------------------------------
###USER-DEFINED PROPERTIES: path, playlist
property path : "~/Desktop/trackdelete.list"
property playlist : "myPlaylist"
--------------------------------------------------------------------------------
property text item delimiters : tab
--------------------------------------------------------------------------------
###IMPLEMENTATION
#
#
tell the deleteList
    if not (its file exists) then return -1

    read

    repeat with i from 1 to the length of its list
        set [its name, its artist, its year] to ¬
            [text item 1, text item 2, text item 3] of ¬
            item i of its list

        delete (playlistItem's track where ¬
            name = deleteList's name and ¬
            artist = deleteList's artist and ¬
            year = deleteList's year)
    end repeat
end tell
--------------------------------------------------------------------------------
###SCRIPT OBJECTS & HANDLERS
#
#
script playlistItem
    property playlist : a reference to the playlist named (my playlist)
    property track : a reference to every track of my playlist
end script

script deleteList
    property application : application "System Events"
    property file : a reference to file (my path) of my application
    property list : null
    property name : null
    property artist : null
    property year : null

    to read
        tell AppleScript to read (my file as alias)
        set my list to the result's paragraphs
    end read
end script
---------------------------------------------------------------------------❮END❯

System info: AppleScript version: "2.7", system version: "10.13.6"