Use iTunes search box to search by ratings

Mar 15, '04 10:15:00AM

Contributed by: Anonymous

For a while I've wanted the ability to refine my song searches in itunes by just using asterisks and I finally decided to do something about it. I've never used AppleScript before (beyond just recording stuff, not much use), so I wrote this by stealing from examples (coming from a C background I find AppleScript syntax easy to read but difficult to synthesize).

tell application "iTunes"
  activate
	
  tell source "Library"
    tell playlist "Library"
      set these_tracks to (every track)
      set the track_count to the count of these_tracks
			
      display dialog "There are " & track_count ¬
      & " tracks. Proceed with rating all of them?" ¬
      buttons {"Don't rate", "Rate"} default button 2
      set the user_choice to the button returned of the result
      if user_choice is "Rate" then
        repeat with I from 1 to the track_count
          set this_track to item I of these_tracks
          if the rating of this_track is 0 then
            set the comment of this_track to "====="
          else if the rating of this_track is 20 then
            set the comment of this_track to "*===="
          else if the rating of this_track is 40 then
            set the comment of this_track to "**==="
          else if the rating of this_track is 60 then
            set the comment of this_track to "***=="
          else if the rating of this_track is 80 then
            set the comment of this_track to "****="
          else if the rating of this_track is 100 then
            set the comment of this_track to "*****"
          end if
        end repeat
      end if
    end tell
  end tell
end tell
Usage:

Things that need changing: Make it so that it only appends the rating rather than erasing the comments. It should replace any previous rating, though. Also, running it from the script editor was slow. The events log showed that in spite of the if else if ladder, it was still checking the rating several more times than I wanted it too.

Comments (3)


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