Can you (semi-)automatically rate all songs with at least X plays with Y stars in iTunes

applescriptitunesmusic

After reconsolidating my music collection in iTunes, I’m curious if there is any way to programmatically set star ratings based upon the number of plays, but only for songs that I have not yet rated?

Specifically, I'd like to set all songs with >1 plays and 0 stars, to 3 stars.

(3 being the average in that I didn't care enough to rate the song lower because I hated it, higher because I liked it, because I was doing something else at the time.)

An AppleScript that I can run occasionally would be sufficient – this way I can passively set song ratings based upon an apathetic impression of the song :).

Best Answer

Create a smart playlist in iTunes with criteria set to all of

  • is Music
  • rated less than 1 star
  • play count greater than whatever count you want

Check “update automatically”. Make sure the contents conform to the list of songs you want to rate automatically. Name it “Unrated Songs” (or similar).

Now create the following AppleScript:

tell application "iTunes"
    set unratedSongs to tracks in (playlist "Unrated Songs")
    repeat with unratedSong in unratedSongs
        set rating of unratedSong to 60
    end repeat
end tell

Save it to ~/Library/Scripts/Applications/iTunes (creating the folders that do not exist yet – note ~/Library is hidden under Lion: use the Finder’s “Go To” menu while pressing Option to get to it or press Cmd+Shift+. in the Save dialog to show hidden folders) as “Rate unrated songs”. You will find the script in iTunes’ script menu, ready to do your bidding.