2012-10-13 33 views
1

任何人你可以指出我爲什麼這個applescript(這是在雪豹工作)不再工作了10.7獅子。文件夾圖像到蘋果公司的iTunes藝術品:不再工作

它打算將每個專輯文件夾中名爲「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

由於圖片格式( 「.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 
相關問題