A replacement script to greatly speed Clutter

May 04, '04 11:56:00AM

Contributed by: Anonymous

Unfortunately, Clutter development seems to be stopped. This little app is the greatest iTunes companion, but with a big library (mine contains 30,000 songs), selecting an album to play was very slow.

Clutter make extensive use of AppleScript to create the playlist that will contain the album you want to listen to. To find the tracks of the corresponding artist and album in your library, the AppleScript routine was scanning every song -- way too slow!

Read the rest of the hint for one solution to this problem...

Inside Clutter's package (Control-click Clutter, select Show Package Contents, then navigate to Contents -> Resources), there's a file called PlayArtistAlbum.scpt. I replaced its content with the following code:

on clutterPlaylist(src)
 tell application "iTunes"
  tell src
   -- Find or create a playlist named "(Clutter)":
   if (first user playlist of src whose name ¬
    is "(Clutter)") exists then
    set pl to first user playlist of src whose name is "(Clutter)"
   else
    set pl to (make new user playlist in src)
    set name of pl to "(Clutter)"
   end if
   return pl
  end tell
 end tell
end clutterPlaylist


on open info
 tell application "iTunes"
  with timeout of 30 seconds
   set theArtist to item 1 of info
   set theAlbum to item 2 of info
   set theTrack to item 3 of info
   if theArtist = "" then set theArtist to null
   --display dialog "theArtist=" & theArtist & ", theAlbum=" & theAlbum
   
   repeat with src in every source
    repeat with pl in every library playlist of src
     set oldShuf to (shuffle of pl)
     -- disable shuffle first
     -- otherwise tracks are copied to dstPl in random order!
     set shuffle of pl to false 
     set dstPl to my clutterPlaylist(src)
     delete tracks of dstPl
     
     set AlbP to (make new playlist with properties {name:("test")})
     repeat with aTr in (search pl for theAlbum only albums)
      if the artist of aTr is equal to theArtist then
       duplicate aTr to AlbP
      end if
     end repeat
     
     duplicate (every track of AlbP) to dstPl
     set n to the number of items of the result
     set shuffle of pl to oldShuf
     
     try
      delete AlbP
     end try
     
     if n > 0 then
      -- Success!
      set view of browser window 1 to dstPl
      
      if theTrack = null or theTrack = "" then
       play dstPl
      else
       play track theTrack of dstPl
      end if
      return true
     end if
    end repeat
   end repeat
   return false
  end timeout
 end tell
end open


on run
 -- for debugging, so it can be run in the Script Editor
 open {"Chet Baker", "My Prince", ""}
end run
Now double-clicking a cover plays the desire album in a second.

[robg adds: This made a notable improvement even with my smaller 3,000 song library. I also chose to make a backup of the existing script first, just in case...]

Comments (8)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040430183813805