# Change the current iTunes song’s rating after it finishes playing

applescriptitunesratingssmart-playlist

I use smart playlists in iTunes. For example: Play only songs rated 4 stars or higher with comments containing "mellow" (I use comments as tags, more or less, so that would be a mellow best-of playlist).

The problem: let's say I'm listening to that playlist and a song starts to play which I decide to drop to 2 stars. The song disappears from the playlist instantly and the playlist stops. What I'd like to happen is, I'd like the song to finish playing and then, after, have the rating change take effect, so that it disappears from the playlist after it finishes playing.

Note: I'm talking about the currently playing iTunes song, not the currently selected song. Since iTunes is probably in the background, the currently selected song could be anything.

I'd prefer an Applescript solution, if possible.

Ideas?

with timeout of 600 seconds
tell application "iTunes"
set cur to current track
repeat until current track is not cur
delay 1
end repeat
set rating of cur to 40 -- 2 stars
end tell
end timeout


This would select the next track and set the rating of the previous track to two stars:

tell application "iTunes"
set cur to current track
next track
set rating of cur to 40
end tell