Collect iTunes Playlist

September 10, 2010

Here’s a handy AppleScript for anyone who occasionally needs to collect all the files of a given playlist into one folder. The only silly requirement is that a track in the playlist must be playing while it’s run (it’s the only way I found how to refer to a “selected” playlist).

So just play a song in the list, run the script and it will prompt you for a destination into which it’ll create a folder named after the playlist and copy all the files into it.

tell application "iTunes"
    set dst to choose folder
    set thePlaylist to current playlist
    set folderName to (name of thePlaylist as string)
    set dst to quoted form of (POSIX path of dst & "/" & folderName)
    do shell script "mkdir " & dst
    repeat with t in every file track of thePlaylist
        set loc to location of t
        set src to (quoted form of POSIX path of loc)
        do shell script "cp " & src & " " & dst
    end repeat
    do shell script "open " & dst
end tell

You can run the script from anywhere you like, but I prefer to keep it in ~/Library/iTunes/Scripts with the name “Collect Playlist”.