将文件添加到iTunes播放列表

时间:2018-04-11 14:57:04

标签: applescript itunes

很抱歉,如果它已经讨论过但我找不到答案。

我想将选择的文件夹中的文件添加到现有的iTunes'播放列表中。 我不想复制/复制这些文件(因此iTunes会在其Music文件夹中创建一个新文件夹)。

如果我使用:

add myFolder to playlist playListName

歌曲在新的“音乐”文件夹中重复

如果我使用:

add myFile to playlist playListName

我有一个类型错误,关于«class cUsP»id 20647 of«class cSrc»id 66 of application“iTunes”。

我的应用程序代码包含几个子程序,除非我发布整个代码,否则不易理解。

可以通过将文件夹放到应用程序或命令选择文件夹来定义myFolder。 然后,从选择文件夹的路径名中提取playListName。

然后,像这样处理文件夹,以创建播放列表:

on processFolder(thisFolder, playListName)
    tell application "iTunes"
        activate
        -------------------------------- create playlist
        try
            set newPlaylist to (make new user playlist with properties {name:playListName})
            set view of browser window 1 to newPlaylist
        on error errMsg
            beep
            my dlog("Unable to create playlist " & my kwote(playListName) & "." & return & return & errMsg, {"Abort"}, appTitle, "error")
            return false
        end try
        --***add thisFolder to newPlaylist -- create new "Music folder" and duplicate files !!!

        --------------- add files --> tracks
        tell application "Finder"
            repeat with thisFile in (get every file of folder thisFolder)
                if (my isValidFile(thisFile)) then
                    tell application "iTunes"
                        try
                            add thisFile to playlist playListName -- ERROR !!!
                        on error errMsg
                            beep
                            my dlog("Unable to add file " & my kwote(thisFile as text) & "." & return & return & errMsg, {"Abort"}, appTitle, "error")
                            return false
                        end try
                    end tell
                end if
            end repeat
        end tell

        return true
    end tell
end processFolder

on isValidFile(thisFile)
    tell application "Finder"
        set the fileInfo to (info for thisFile as alias)
        if (mp3Check) then
            if (alias of the fileInfo is false) and ((the file type of the fileInfo is in the typesList) or (the name extension of the fileInfo is in the extensionsList)) then return true
        else
            if (alias of the fileInfo is false) then return true
        end if
        return false
    end tell
end isValidFile

谢谢。

0 个答案:

没有答案