2014-03-04 29 views
-1

好吧,坦白说,我不知道我在做什么。我从我下载的脚本中借了很多代码。我试图弄清楚我的代码到底出了什么问题。起初,它不会编译,然后我欺骗到最后这样做(基本上删除它说的是错误的任何东西)第一次applescript编码问题

现在,超过2/3的我的代码是灰色的,将无法正常工作。所以没有进一步ado-这里它是:

property progress_factor : 200 
property separator : "-" 
tell application "iTunes" 

    display dialog "\"Create Artist Folder\" 

    set lib to library playlist 1 
    set numAllTracks to (get count of lib's file tracks) 
    set everyPlaylist to (get name of every user playlist) 

    set the count to 0 

    set ofi to fixed indexing 
    set fixed indexing to true 

    try 
     with timeout of 300000 seconds 
      repeat with i from 1 to numAllTracks 

       set thisTrack to (get a reference to file track i of lib) 

       tell this Track to set {art, alb, dbid} to {get Artist as string, get database ID} 

       if (art is not) then 
        set new_playlist_name to (art) as text 
       else if 
        set new_playlist_name to " * " 
       end if 

       --make new playlist if it doesn't exist 
       if everyPlaylist does not contain (new_playlist_name as text) then 
        set newPlaylist to (make playlist with properties {name:new_playlist_name}) 
        set end of everyPlaylist to new_playlist_name 
       end if 
      -- Cycle through playlists of main library 
       set thisPlaylist to (get a reference to file playlist i of lib) 

      -- get Playlist properties 
       tell thisPlaylist to set {art} to {get artist as string, get database ID} 

      -- Folder Playlist to put Playlist 
       if (art is not) then 
        set new_folderplaylist_name to (art) as text 
       else if 
        set new_FolderPlaylits_name to " * various or unnamed 

    -- make new Folder Playlist if it doesn't exist 
    if everyFolderPlaylist does not contain (new_folderplaylist_name as text) then 
     set newFolderPlaylist to (make FolderPlaylist with properties {name:new_folderplaylist_name}) 
    end if 
    set thecount to thecount + 1 


    set fixed indexing to ofi 
    if frontmost then 
     if gave up of (display dialog "Done" buttons {"Yay!"} ¬ 
      default button 1 with icon 1 giving up after 300) then error number -128 
    end if 
end tell 

我真的很感谢每一点帮助。我也意识到这在新的iTunes中并不是一个完全必要的功能,但我真的想写自己的。

谢谢!

+0

该脚本的预期行为是什么?发生了什么呢? –

回答

0

试试这个:

property progress_factor : 200 
property separator : "-" 
tell application "iTunes" 

    display dialog "Create Artist Folder" 

    set lib to library playlist 1 
    set numAllTracks to (get count of lib's file tracks) 
    set everyPlaylist to (get name of every user playlist) 

    set the count to 0 

    set ofi to fixed indexing 
    set fixed indexing to true 

    try 
     with timeout of 300000 seconds 
      repeat with i from 1 to numAllTracks 

       set thisTrack to (get a reference to file track i of lib) 

       tell thisTrack to set {art, alb, dbid} to {get artist as string, get database ID} 

       if (art is not "") then 
        set new_playlist_name to (art) as text 
       else 
        set new_playlist_name to " * " 
       end if 

       --make new playlist if it doesn't exist 
       if everyPlaylist does not contain (new_playlist_name as text) then 
        set newPlaylist to (make playlist with properties {name:new_playlist_name}) 
        set end of everyPlaylist to new_playlist_name 
       end if 
       -- Cycle through playlists of main library 
       set thisPlaylist to (get a reference to file playlist i of lib) 

       -- get Playlist properties 
       tell thisPlaylist to set {art} to {get artist as string, get database ID} 

       -- Folder Playlist to put Playlist 
       if (art is not "") then 
        set new_folderplaylist_name to (art) as text 
       else 
        set new_FolderPlaylits_name to " * " 
       end if 
      end repeat 
     end timeout 
    end try 

    -- make new Folder Playlist if it doesn't exist 
    if everyFolderPlaylist does not contain (new_folderplaylist_name as text) then 
     set newFolderPlaylist to (make FolderPlaylist with properties {name:new_folderplaylist_name}) 
    end if 
    set thecount to thecount + 1 


    set fixed indexing to ofi 
    if frontmost then 
     if gave up of (display dialog "Done" buttons {"Yay!"} ¬ 
      default button 1 with icon 1 giving up after 300) then error number -128 
    end if 
end tell 

长话短说,你忘了放了一堆end语句,你错过了一对夫妇收盘报价。