applescriptitunesitunesartwork

Applescript editor not responding


I did the following script in order to identify itunes songs that doesn't have artwork. It's based on other script that I found in net.

tell application "iTunes"
   repeat with a in every track of playlist "Library"
      if not (exists (artwork 1 of a)) then
         add (get location of a) to (playlist "noart")
      end if
   end repeat
end tell

It seems to be working, it compiles well, and because I can that it in event log windows:

tell application "iTunes"
    count every track of playlist "Library"
        --> 10684
    exists artwork 1 of item 1 of every track of playlist "Library"
        --> true
    exists artwork 1 of item 2 of every track of playlist "Library"
        --> true

But after 4 hundred tracks, it starts to run slowly, and applescript stops responding after one thousand tracks.

I thought that maybe I could be exhausting my mac memory, but in Activity Monitor, I can see that Applescript is consuming 100% CPU and less than 50MB of memory. I'm running macos 10.7.4 on a macbook pro (i7 with 4GB ram).

As you can see my itunes library has 10684 tracks. It's not a small library, but it's not a huge one.

Does anyone has any advice? Or a script to identify tracks without artwork?

TIA,

Bob


Solution

  • Here's what I use. My main suggestion would be to use "duplicate" instead of "add" and then you do not need to get the location of a track. Also you'll see I'm using "a reference to" most things which makes it work faster. I also create the "no artwork" playlist with a time stamp on-the-fly so I can see when I ran the script.

    set d to current date
    set missingTracksCount to 0
    tell application "iTunes"
        set isFixedIndexing to fixed indexing
        if not isFixedIndexing then set fixed indexing to true
    
        -- make a new playlist to hold the tracks
        set newPlaylist to make new playlist
        set name of newPlaylist to "No Art - " & month of d & " " & day of d & " " & time string of d
    
        set mainPlaylist to a reference to playlist "Library"
        set noArtworkPlaylist to a reference to newPlaylist
    
        set trackCount to count of tracks of mainPlaylist
        repeat with i from 1 to trackCount
            set trackRef to (a reference to (track i of mainPlaylist))
            if (count of artworks of trackRef) is less than 1 then
                duplicate trackRef to noArtworkPlaylist
                set missingTracksCount to missingTracksCount + 1
            end if
        end repeat
    
        if not isFixedIndexing then set fixed indexing to isFixedIndexing
    
        display dialog "Finished!" & return & (missingTracksCount as text) & " tracks didn't have artwork." buttons {"OK"} default button 1 with icon note giving up after 5
    end tell