在iTunes applescript中使用转换后的曲目

时间:2017-01-15 15:24:35

标签: macos applescript itunes

我有一个脚本可以遍历播放列表中的曲目。如果它们已经是mp3,则将它们添加到我的iPod(duplicate currentTrack to ipod_lib)并将其从播放列表中删除 - 这部分工作正常。如果它们无损,我想将它们转换为mp3并将它们添加到我的iPod而不是自己添加无损文件,因为它们太大了。第duplicate convertedTrack to ipod_lib行会引发以下错误...

错误" iTunes收到错误:无法将源ID 235166的库播放列表ID 270897设置为{源ID为68的库播放列表ID 38702的文件轨道ID 322339}。"来自源ID为235166的库播放列表ID 270897的编号-10006

http://dougscripts.com/

上的脚本中提取locateiPods代码

真的不确定我在这里做错了什么......

on locateiPods()
    set the volumes_directory to "/Volumes/" as POSIX file as alias
    set the volume_names to list folder volumes_directory without invisibles
    set mounted_iPods to {}
    repeat with i from 1 to the count of volume_names
        try
            set this_name to item i of volume_names
            set this_disk to ("/Volumes/" & this_name & "/") as POSIX file as alias
            set these_items to list folder this_disk
            if "iPod_Control" is in these_items then
                set the end of the mounted_iPods to this_disk
            end if
        end try
    end repeat

    -- check for iPod count
    if the mounted_iPods is {} then
    --
        try
            display dialog "iPod is not mounted." buttons {"Cancel"} with icon 0 giving up after 15
        on error
            error number -128
        end try

    else if the (count of the mounted_iPods) is greater than 1 then
        -- choose iPod
        set the ipod_names to {}
        repeat with i from 1 to the count of the mounted_iPods
            set this_iPod to item i of the mounted_iPods
            tell application "Finder"
                set the end of the ipod_names to the name of this_iPod
            end tell
        end repeat
        tell application "iTunes"
            activate
            set this_name to (choose from list ipod_names with prompt "Pick the iPod to use:") as string
        end tell
        if this_name is "false" then error number -128
            repeat with i from 1 to the count of the ipod_names
                if item i of the ipod_names is this_name then
                    set this_iPod to item i of the mounted_iPods
                    exit repeat
                end if
            end repeat
    else
        set this_iPod to item 1 of the mounted_iPods
    end if
    return this_iPod
end locateiPods

tell application "iTunes"
    set allTracks to every track in user playlist "TEST"
    set the_iPod to my locateiPods() -- this is a path
    set the_iPod_name to text 1 thru -2 of (the_iPod as string)
    set ipod_src to some source whose name is the_iPod_name
    set ipod_lib to library playlist 1 of ipod_src

    repeat with i from 1 to count of allTracks
        set currentTrack to item i of allTracks
        set fileType to kind of currentTrack as string
        if fileType is "MPEG audio file" then
            duplicate currentTrack to ipod_lib
            tell playlist "TEST" to delete contents of currentTrack
        end if
        if fileType is "Apple Lossless audio file" then
            set convertedTrack to convert currentTrack
            duplicate convertedTrack to ipod_lib
        end if
    end repeat
end tell

似乎执行以下操作使其工作,这表明convertedTrack不属于track类型

set convertedTrack to convert currentTrack
repeat with theTrack in convertedTrack
    duplicate theTrack to ipod_lib
end repeat

1 个答案:

答案 0 :(得分:0)

我总是使用“convert”作为曲目列表,然后结果是曲目列表。顺便说一下,转换轨道列表而不是循环转换每个轨道要快得多。也许你应该首先选择所有种类无损的曲目。

关于转换,请注意转换会转换为iTunes首选项中设置的格式。然后您的脚本将取决于这些首选项。我建议,为了更安全,保存当前首选项,将转换模式设置为您想要MP3的格式,然后将首选项重置为之前的状态。您可以使用以下脚本:

-- get & save current encoder
tell application "iTunes" to set Encoder_Base to name of current encoder

-- change encoder to MP3
tell application "iTunes" to set current encoder to (get first encoder whose name contains "MP3")

此外,您可以使用Source方法优化iPod子程序,而不是查找已装入的卷。 iTunes类型的源提供了一种有效的方式:

-- kind of source could be : library, iPod, audio CD, MP3 CD, radio tuner, shared library, iTunes Store
tell application "iTunes"
set myList to every source whose kind is iPod
if myList is {} then
    display alert "no ipod connected"
    return
else -- I assume if one iPod found, there is only 1 connected !!
    set SourceName to name of first item of myList
    set SourceID to id of first item of myList
end if
end tell

我希望它有所帮助。