An AppleScript to copy iPod ratings back to iTunes

Oct 28, '04 09:13:00AM

Contributed by: fivefifty

I recently moved from the US to the UK, and brought my iPod with me. I got a new computer, and so I copied my music from my iPod to iTunes (since I wanted all the songs, I just used cp -R from the hidden iPod_Control folder to my Music folder). Unfortunately, this does not copy things like ratings, comments, play count, etc.

Thus I created the following AppleScript...

Enter the following in Script Editor, then save it to your Scripts folder...

tell application "iTunes"
  set trackList to get selection
  
  repeat with sourceTrack in trackList
    set sourceData to (get {name, artist, album} of sourceTrack)
    set copyData to (get {played date, played count, rating} ¬
      of sourceTrack)
    set addSourceData to (get {time, size, year, bit rate} ¬
      of sourceTrack)
    
    set trackList to (every track of playlist "Library" whose ¬
      ((name is item 1 of sourceData) ¬
      and (artist is item 2 of sourceData) ¬
      and (album is item 3 of sourceData) ¬
      and (time is item 1 of addSourceData) ¬
      and (size is item 2 of addSourceData) ¬
      and (year is item 3 of addSourceData) ¬
      and (bit rate is item 4 of addSourceData)))
    
    repeat with destTrack in trackList
      if (item 1 of copyData is not equal to missing value) then
        set played date of destTrack to item 1 of copyData
      end if
      if (item 2 of copyData is not equal to missing value) then
        set played count of destTrack to item 2 of copyData
      end if
      set rating of destTrack to item 3 of copyData
    end repeat
  end repeat
end tell
Basically, you navigate to your (manually updated) iPod inside of iTunes, select the tracks from which you want to copy ratings, played count, and last played for, and the script finds the corresponding track in your library and copies the data. In fact, it also works from shared music as well (assuming you have the exact same song file as the sharer).

If you want anything besides these three fields (I left out enabled, comment, volume adjustment, EQ, start, finish, and modification date), add the field name to the list of field names defining copyData, and also set the field name in the final repeat, noting that I had trouble when a field had a value of "missing value."

I got the idea and method for this script from a program called Synch iPod-iTunes Data, but it was unreliable for me, and would only copy data for songs that had a last play date.

Comments (3)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20041026135515414