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

Using converted tracks in iTunes applescript

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

错误 "iTunes got an error: Can’t set library playlist id 270897 of source id 235166 to {file track id 322339 of library playlist id 38702 of source id 68}." 来自库播放列表 id 270897 的编号 -10006,来源 id 235166

locateiPods 代码是从 http://dougscripts.com/

上的脚本中提取的

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

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

我总是使用 "convert" 作为曲目列表,结果是曲目列表。顺便说一句,转换曲目列表比循环转换每个曲目要快得多。也许你应该首先对所有无损类型的曲目进行 select。

关于转换,还请记住转换会转换为您在 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")

此外,也许您可​​以使用源方法优化您的 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

希望对您有所帮助。