Copy music to iPod based on recent iTunes playback

Sep 25, '08 07:30:02AM

Contributed by: Anonymous

My iTunes library is much larger than the capacity of a 4GB (or even 8GB) Flash-memory-based iPod. Therefore I searched for a solution that would allow me to automatically copy a selection of songs I'm actually listening to over to my iPod. I didn't want to bother changing the playlist I am syncing with the iPod manually every week or so.

The solution was based on this AppleScript snippet I found on the Internet, with some changes to make it work the way I wanted it to work. The script adds albums to a playlist based on the songs I recently played. In that way, the iPod is always filled with the music I'm enjoying right now. 2br Here is the script:

with timeout of 1000 seconds
    tell application "iTunes"
        if exists user playlist "Copy to iPod" then
            delete every file track of user playlist "Copy to iPod"
        else
            make new user playlist at folder playlist "Test" with properties {name:"Copy to iPod"}
        end if
        repeat with aTrack in (file tracks of user playlist "Recently played for iPod")
            set tempAlbum to album of aTrack
            --Make sure we haven't already added this album
            set testAlbum to count (every file track of user playlist "Copy to iPod" whose album is tempAlbum)
            if testAlbum = 0 then
                -- Nope, it's not in the playlist
                -- Let's check and see if there's room to add it
                -- Edit the next row (after: is less than) to set the maximum size limit. 15 GB for example is 1.5E+10, 7GB is 7E+9
                if (size of user playlist "Copy to iPod" is less than 7.5E+9) then
                    duplicate (every file track of library playlist 1 whose album is tempAlbum) to user playlist "Copy to iPod"
                else
                    exit repeat
                end if
            end if
        end repeat
    end tell
end timeout
To use this script, you need to create two playlists: One smart playlist called Recently played (for iPod), with time-based selection limits (like the built-in Recently Played playlist), and whatever other conditions you want to apply (e.g. no audio books). The ability to add my own conditions is why I used my own version of the Recently Played playlist, instead of the provided version. The second playlist is a standard playlist called Copy to iPod. The Copy to iPod playlist is the one that will be synced with the iPod.

The major drawback is that you have to play a song first in iTunes (playcount must be raised) before the album containing the song will be copied to the iPod.

[robg adds: I haven't tested this one. ]

Comments (12)


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