将文件夹映像到AppleScript中的iTunes插图:不再工作了

时间:2012-10-13 07:09:49

标签: applescript mp3 itunes

你们中的任何人都可以指出为什么这个AppleScript(正在使用雪豹)在10.7 Lion上不再有用。

它打算将每个相册文件夹中名为“folder.jpg”的文件复制到iTunes中所选mp3的ID3标签中。

property tempfile : ((path to temporary items as string) & "itunespicturefile_temporaire.pict")
global vPictFolder


tell application "iTunes"
    set v_TrackSelection to selection
    if v_TrackSelection is not {} then
        repeat with vTrack in v_TrackSelection
            set vPictFolder to my (ParentFromPath(location of vTrack as string)) as text
            set thisPict to my getpictData("folder.jpg")
            if thisPict is not "" then
                delete artworks of vTrack
                set data of artwork 1 of vTrack to (thisPict)
            end if
        end repeat
    else
        display dialog ("select tracks first !")
    end if
end tell

on getpictData(vAlbumpictName)
    tell application "Finder" to tell file vAlbumpictName of folder vPictFolder to if exists then
        set t_file to it as string
    else
        display dialog vPictFolder & vAlbumpictName
        return ""
    end if
    do shell script "/opt/local/bin/convert " & quoted form of POSIX path of t_file & " " & quoted form of POSIX path of tempfile
    display dialog "ok"
    return read (tempfile as alias) from 513 as picture
end getpictData

on ParentFromPath(thePath)
    set wantPath to true
    set thePath to (thePath as text)
    set saveDelim to AppleScript's text item delimiters
    set AppleScript's text item delimiters to {":"}
    set pathAsList to text items of thePath
    if the last character of thePath is ":" then
        set idx to (the number of text items in thePath) - 2
    else
        set idx to -2
    end if
    if wantPath then
        set folderName to ((text items 1 through idx of pathAsList) as text) & ":"
    else
        set folderName to item idx of pathAsList
    end if
    set AppleScript's text item delimiters to saveDelim
    return folderName
end ParentFromPath

1 个答案:

答案 0 :(得分:1)

因为Lion和较新的操作系统不支持图片格式(“ .pict ”)。 您可以使用术语picture来读取图像文件(JPEG,PNG,...),格式不是Picture格式,而是文件的原始格式。

tell application "iTunes"
    set v_TrackSelection to selection
    if v_TrackSelection is not {} then
        repeat with vTrack in v_TrackSelection
            set vPictFolder to my (ParentFromPath(location of vTrack as string)) as text
            set thisPict to my getpictData(vPictFolder & "folder.jpg")
            if thisPict is not "" then
                delete artworks of vTrack
                set data of artwork 1 of vTrack to (thisPict)
            end if
        end repeat
    else
        display dialog ("select tracks first !")
    end if
end tell

on getpictData(tFile)
    try
        return (read (tFile as alias) as picture)
    end try
    display dialog tFile
    return "" -- not exists
end getpictData