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.
•
[5,709 views]

