Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use iTunes search box to search by ratings Apps
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:
  • If you want all the songs by an artist with an exact rating you can type the whole thing in. "eric clapton ****+" gives you all the songs with rating 4.
  • If you only want to specify a minimum rating you can just type the stars. "***" will match songs with rating 3 or higher.
  • If you want to specify a maximum rating you specify it with plus signs. "+" will match any song rated 4 or lower.
  • You can specify a range by mixing them. "**+" will get you songs with at least 2 stars but no more than 4.

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.

    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[5,666 views]  

Use iTunes search box to search by ratings | 3 comments | Create New Account
Click here to return to the 'Use iTunes search box to search by ratings' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use iTunes search box to search by ratings
Authored by: dogboy on Mar 15, '04 11:42:42AM

Or you could just click on the Rating column in iTunes. Or set up a smart playlist for each rating.



[ Reply to This | # ]
Use iTunes search box to search by ratings
Authored by: DougAdams on Mar 15, '04 11:50:37AM
This works on the selected tracks:
tell application "iTunes"
	if selection is not {} then
		set these_tracks to a reference to selection
		set the track_count to the count of these_tracks
		if button returned of (display dialog "There are " & track_count & 
			" tracks. Proceed with rating all of them?" buttons {"Don't rate", "Rate"} default button 2) is "Rate" then
			repeat with i from 1 to the track_count
				set this_track to item i of these_tracks
				
				set newRating to {"=", "=", "=", "=", "="}
				set c to 1
				repeat ((rating of this_track) div 20) times
					set item c of (newRating as list) to "*"
					set c to c + 1
				end repeat
				set comment of this_track to newRating as string
			end repeat
		end if
	end if
end tell


[ Reply to This | # ]
Use iTunes search box to search by ratings
Authored by: podd on Mar 19, '04 05:39:43PM
Using Python:

#!/usr/local/bin/pythonw

import re
from appscript import *

for track in app('iTunes.app').selection.get():
	rating = track.rating.get() // 20
	comment = track.comment.get()
	comment = re.sub(' [=*]{5}$', '', comment) # remove existing 'rating', if any
	comment += ' ' + '*****====='[5 - rating:10 - rating] # append new 'rating'
	track.comment.set(comment)
(Requires MacPython 2.3+ and appscript.)

[ Reply to This | # ]