The mother of all smart iTunes radio stations

Okay, I’m going to write this one in English, because it’s probably useful for many people out there who don’t speak German.

Based on the „Smart Radio“ playlist idea here, the (non-existing) ultimate iTunes script described here and using this script as a starting point, I decided to roll my own ultra-smart iTunes personal radio.

Some of the highlights:

  • You don’t have to rate any music in advance – the script auto-rates the music as you play it – the more often you play a song, the higher its rating will be
  • You can use your current ratings as a starting point if you want to.
  • Recently added music is preferred
  • It’s possible to exclude unwanted songs.
  • Doesn’t rely on hard-coded playcounts, so it doesn’t require regular maintenance
  • If you don’t listen to a high-rated song for awhile, its rating will automatically be lowered.

The caveats:

  • It wonly works on Macs – sorry Windows folks.
  • The script will change your music’s rating! Don’t use it if you don’t want that to happen.
  • It’ll only be useful if you’re primarily using iTunes to listen to your music – if you’re more of an iPod person, this is not for you.
  • You need to have an Applescript running in the background. (it doesn’t use much resources, though.)
  • You need to install the Anacron package – the install is painless and IMHO Anacron should be installed on every Mac anyway.

And a last warning – this is a bit advanced stuff. You should be familiar with smart playlists, AppleScript and a bit of shell stuff if you attempt this.

Read more – a lot more – after the jump.

The setup
First a bit of theory: My script uses the ratings system as a way to measure how much you like a song at the moment – if you play it a lot, its rating will rise. If you’re getting sick of it and skip it, the rating will sink again.

How is this accomplished? I’ll walk you through it step by step:

1. Install Anacron
To make sure our regular task of downgrading songs we haven’t heard in awhile gets executed even if the system is not running 24/7, we use the wonderful Anacron package (which also makes sure that some imprtant OS X housekeeping jobs are taken care of). Grab it here for Tiger (10.4) or here if you’re still using 10.3 or below. It’s a simple install, come back when you’re done. :-)

2. Create a core playlist
This is the master playlist – anything that’s on this playlist will be played, anything that’s not on there will be ignored by our radio.

Personally, I use a smart playlist that excludes anything shorter than 1 minute, anything longer than 10 minutes, any of the QuickTime moves I happen to have in my library („Kind does not contain ‚QuickTime'“) and also exclused some genres – like „Spoken Word“ that I just don’t want on my personal radio. You could go a completely different route, e.g. only include certain genres – it’s up to you. Don’t use selection based on ratings – that’d break the logic the script relies upon.

After you finised creating that playlist, call it @@core@@ (The @-signs put it at the top of the list in iTunes‘ playlist display. You could call it anything else, but I’m sticking with „@@core@@“ :-) )

3. Create a playlist for recently added music
Fresh and unknown music should be preferred – that’s why we have a special area for it. I call it @@new@@ and it looks like this:

  • Apply all rules
  • Playlist is @@core@@
  • Added within the last 2 months
  • Playcount is 0

Later on, when we create the radio playlist, every song in @@new@@ will automatically be included.

4. Create a playlist for „semi-stale“ music
The system’s design makes it possible for songs to be played once and then rot in some waiting place for awhile without being played. To counter that (and make automatic downgrading possible), we need a list for rated music that hasn’t been played in awhile. (Remember – our script is going to take over the rating, so basically anything that’s been rated must have been touched by it.)


  • Apply all rules
  • Playlist is @@core@@
  • Playlist is not @@new@@
  • Not played within the last 2 weeks
  • Rating is greater than 0 stars

5. Create the ratings playlists
We want to have a Radio playlist that feeds off @@core@@, but it should honor the ratings system: Songs we like should be played more often, some new or forgotten music should be infused, as well, etc. To make that possible we need a filtering layer between the Radio playlist and @@core@@. We also want to exclude songs in the @@new@@ playlist, since those will be included within our master radio playlist anyway.

The first list in that filtering layer contains unrated music. In my model, unrated songs are either songs you never heard before or those you haven’t played in a long time. I call it @@0 Stars (a)@@ and it looks like this:

  • Apply all rules
  • Playlist is @@core@@
  • Playlist is not @@new@@
  • My rating is 0 stars
  • Limit to 50 songs selected randomly

(You might want to tweak the limit number later on when the system is in use, but I found 50 to be a nice starting point.)

Why did I call it @@0 Stars (a)@@ instead of just „@@0 Stars@@“. Very simple: Because there’s a @@0 Stars (b)@@, as well.

iTunes‘ star rating isn’t very fine grained, but it’s just the frpnt-end for a more sophisticated ratings system: You can rate a song anything from 0 to 100 – each star in iTunes corresponds to a 20 point increase. (1 star: A rating of 20 points, 2 stars = 40 points, etc.) iTunes will round the number of stars displayed: If you have song rated 44, iTunes will display 2 stars. That song, however, won’t show up in a smart playlist designed to show every 2-star-song, because iTunes‘ filtering is designed to look for the exact number of points – so it’ll only display songs with exactly 40 points.

To be able to use the „fuzzy“ ratings in between, we need to create a rather curious looking playlist: @@0 Stars (b)@@

  • Playlist is @@core@@
  • My rating is greater than 0 stars and less than 1 star
  • Limit to 50 songs selected by least recently played

One would expect this playlist not to match anything, however it actually matches every song with a rating between 0 and 20 points – exactly what we need.
(Update: According to user feedback, this trick isn’t necassary any more in iTunes 6.0.3 since it’ll automatically include all numbers in the range in a smart playlist. I didn’t try it out myself yet, but if that’s true, you should be able to leave out all of the (b)-lists in 6.0.3 or above and still have the same functionality.)
Note that while the first playlist is odered randomly, this (and all subsequent) playlists are ordered by most recently played This – coupled with the numer limit – makes sure that songs have a small „cooling off“ period before being played again. (Since the playlists for the higher ratings are larger, higer rated songs are repeated more frequently than lower rated songs.)

Here are the other ratings playlists:

@@1 Star (a)@@

  • Apply all rules
  • Playlist is @@core@@
  • Playlist is not @@new@@
  • My rating is 1 star
  • Limit to 13 songs selected by least recently played

@@1 Star (b)@@

  • Apply all rules
  • Playlist is @@core@@
  • My rating is greater than 1 star and less than 2 stars
  • Limit to 12 songs selected by least recently played

@@2 Stars (a)@@

  • Apply all rules
  • Playlist is @@core@@
  • My rating is 2 stars
  • Limit to 25 songs selected by least recently played

@@2 Stars (b)@@

  • Apply all rules
  • Playlist is @@core@@
  • My rating is greater than 2 stars and less than 3 stars
  • Limit to 25 songs selected by least recently played

@@3 Stars (a)@@

  • Apply all rules
  • Playlist is @@core@@
  • My rating is 3 stars
  • Limit to 50 songs selected by least recently played

@@3 Stars (b)@@

  • Apply all rules
  • Playlist is @@core@@
  • My rating is greater than 3 stars and less than 4 stars
  • Limit to 50 songs selected by least recently played

@@4 Stars (a)@@

  • Apply all rules
  • Playlist is @@core@@
  • My rating is 4 stars
  • Limit to 100 songs selected by least recently played

@@4 Stars (b)@@

  • Apply all rules
  • Playlist is @@core@@
  • My rating is greater than 4 stars and less than 5 stars
  • Limit to 100 songs selected by least recently played

@@5 Stars@@

  • Apply all rules
  • Playlist is @@core@@
  • My rating is 5 stars
  • Limit to 400 songs selected by least recently played

Again – all the limit numbers are guesstimates – you might want to tweak them after using the script for a bit. The general idea is that there should be more room for high rated songs than for the lower ratings.

6. Create the master Radio playlist

Okay, this is our radio playlist, called @@@Radio@@@. (Note that it doesn’t access @@core@@ directly – it uses the „filtering layer“ of our smart playlists.)

  • Apply some rules
  • Playlist is @@new@@
  • Playlist is @@old@@
  • Playlist is @@0 stars (a)@@
  • Playlist is @@0 stars (b)@@
  • Playlist is @@1 star (a)@@
  • Playlist is @@1 star (b)@@
  • Playlist is @@2 stars (a)@@
  • Playlist is @@2 stars (b)@@
  • Playlist is @@3 stars (a)@@
  • Playlist is @@3 stars (b)@@
  • Playlist is @@4 stars (a)@@
  • Playlist is @@4 stars (b)@@
  • Playlist is @@5 stars@@

Make sure you’re setting it to only match some rules, no song is ever going to match all of those rules.

7. Create Housekeeping playlists
Our script needs two playlists for internal use: A „recently“ played smart playlist and a regular playlist to store the last song it caught:

@@recently played@@

  • Playlist is @@core@@
  • Limit to 1 songs order by most recently played

Next, create a regular (non-smart) playlist named „@@current song@@“ and leave it empty. The script needs it for its own dark purposes. :-)

8. Create the scripts
We have two scripts: One that’s running in the background, rating your music as you play it, and one that’s started once a week to downgrade the „semi-stale“ music.

Here they come:

First our background rating skript – the brain of the operation:

Save this in script editor as an application called Rating and make sure you check the box that says „don’t terminate automatically“ or something like that.

The second script is needed for downgrading stale songs. Every time it’s called, it’ll reduce the rating of all songs in your @@old@@ playlist by 1 star.

Save this as a plain application called „Purge“. (Don’t check the „don’t terminate“ box.)

9. Make „Purge“ callable
We want to call „Purge“ via Anacron. Anacron runs as root, but we want our script to be run as out user. A small bash script does the trick:


sudo -u <USERNAME> osascript /<PATH>/<TO>/

(Substiute your username and the path to your Purge application in the indicated places.)

Save the script as

Now, open a Terminal window, and type sudo pico /etc/anacrontab.
Enter your password when asked.
In the anacrontab file, ass the following line:

7       10      purge.weekly    /<PATH>/<TO>/

(Again, substitute the correct path to your
Press Ctrl-X to exit the editor. It asks you if you want to save the changes - press "Y" to save them.

From now on, will be run weekly - downgrading anything in your @@old@@ list.

10. Start the Rating app
Just double-click your - it shoud stay running. You probably want to add it as a startup item - make sure iTunes is started before the Rating script.

11. Test it
Play an unrated song from the @@@Radio@@@ playlist - wait until it finihes (or, if you're impatient, jump close to the end of the track, but make sure it plays for at least 10 seconds.)
A few seconds after the next song starts, the previous song's rating should change to "2 stars".

If it doesn't work, add a comment below, hopefully, we'll figure it out. :-)

12. Hints:

  • It'll take awhile to fill up all the lists - you can speed this up by pre-rating songs.
  • You can change a song's rating manually anytime - that way you can influence how often it'll be played.
  • I like to use the @@@Radio@@@ list with the "Party Shuffle" feature - just use @@Radio@@ as the source - if the script is running - the rating will take care of itself.
  • If you know your way around AppleScript and/or smart playlists, Tweak the numbers to your liking - any numbers are fair game. :-)
  • You can create a dynamic "Top 20" playlist:
    • Playlist is @@@Radio@@@

    • Limit to 20 items order by Ratings, highest first

    This'll even sort by the "real rating, so a song with a rating of "40" will always be below a song with a rating of "49", even though both have 2 stars displayed.

13. The way of a song through all of this
Here's what happens to a song within this maze of scripts and lists:

  • The script polls iTunes every 10 seconds to check which song is playing. It remembers that song by putting it into the @@current song@@ playlist.
  • As soon as it detects a new song, it checks @@recently played@@ to see if the previous song was finished or if the user skipped ahead.
  • If the song was finished, the skript upgrades its rating: Unrated songs go straigt to 2 stars. If the song already has a rating, it'll advance slower the higher the rating is. You need to really like a song to promote it to 5 stars.
  • If the song was skipped, it is downgraded. If it has 1 star, it's downgraded to "unrated", if it has more, it'll be downgraded 10 points ("half a star").
    Exception:If an unrated song gets skipped, it is rated with 1 star. Why? If it stayed unrated, it'd never get out of the@@0 stars@@ playlist, therefore it'd stay in @@@Radio@@@ forever - not good if you don't like it. By rating it with 1 star, it's moved out of @@0 stars (a)@@, making room for a new song. It'll either come up again in shuffle mode where you can either skip it again (demoting it to "unrated" a d banning it off @@Radio@@ until chance puts it back onto @@0 stars (a)@@ or - if you like it (and listen to it until the end, it'll be upgraded, putting it into the regular cycle.
  • If a song is rated with more than 0 stars but hasn't been played for more than 2 weeks, it's put on @@old@@
  • Any song that was added within the last 2 months and has never been played, wille be put onto the @@new@@playlist, makeing it more likely to turn up in your @@@Radio@@@ playlist.

14. What's left?
Well, that was my setup - there are a lot of things to tweak and change, so feel free to experiment and share your results in the comments. :-)

Oh, and feel free to subscribe to my English RSS feed to receive future English language postings to the site. :-)

18 Responses to “The mother of all smart iTunes radio stations”

  1. Baumi sagt:

    I updated to iTunes 7.0.2 a while ago, and everything works fine. Actually, AFAIK iTunes always waited till the end to count a track as played, Pdcasts being the only exception. Have you been trying to use the script on Podcasts?

  2. […] des Gedanken: Gerade hat mein iTunes-Radio-Setup eine alte Eurovisions-Schnulze namens “It’s nice to be in love again” […]

  3. […] around with me (it’s amazing how much music one can buy over 25 years). Mucking about with smart playlist systems I’ve built a fairly respectable radio that pulls solely from my own music. The problem is […]

  4. Anonymous sagt:

    Could you please post instructions on how to update the script for 10.4, I’m talking about using launchd instead of installing anacron. Also, would there be a way to have the Rating application as a bash script running automatically instead of an application showing on the dock all the time?

  5. Undertrader sagt:

    I love this script. I’ve added a few things to it to improve it a bit.

    I created a smart playlist of Comedy bits, limited to 5 and under 4 minutes and named it @@Comedy@@ and another playlist called „Sound Clips“ that are quotes from movies and TV shows, limited to 5 under 1 minute and named it @Clips@ and added those to the Radio script.

    Then I also use the Play AP Newspulse script from Doug’s Applescripts to get the news to play every hour as well.

    Great script, thank you so much!

  6. Undertrader sagt:

    One more thing, if you change the recently played script to check the Music Library, rather than @core@ you can create new smart playlists and have them rated too. For example:

    @@ Top Hits @@
    Playlist is @@ 4 star @@
    Playlist is @@ 5 star @@

    Or Christmas
    Genre is @@ Holiday @@

  7. Baumi sagt:

    I actually added an option for a Holiday playlist to my personal script, as well. However, I actually change @core@ instead of the script. All a matter of preference, I guess. :-)

  8. verboEse sagt:

    Good idea. I fetched it a year or two ago and modified it a lot: first I have no need of a „purge“ script, as my „rating“ program does both: completed songs get a higher rating and skipping a title will lower the rating. If a rating goes near null, it will unmark the song so it’s no longer includes in @@core@@. It runs well on our >7k songs big core-list. If you do allow me to, I will publish my script on my website.