iTunes Playlist Track Export AppleScript
Mac OS X
— 16 Jun 2009 14:39 — 408 days ago
I wanted to export all tracks of an iTunes playlist into a folder, but iTunes’ export feature only exports the track list (as XML or plain text file), not the actual music files.
Drag-and-drop from the iTunes window to the Finder folder window works but doesn’t preserve the playlist order, and the filenames are messy because of the leading track numbers.
I wrote this AppleScript that reads the XML export track list file and copies the tracks to a folder on the desktop. It strips leading numbers from the filenames and adds new ones corresponding to the playlist order.
on open (theFiles)
set theFile to item 1 of theFiles
set myUrls to {}
tell application "System Events"
set myContents to contents of property list file (theFile as string)
tell myContents
tell property list item "Playlists"
tell property list item 1
tell property list item "Playlist Items"
repeat with aPlaylistEntry in property list items
set aTrackId to |Track ID| of (value of aPlaylistEntry as record)
tell property list item "Tracks" of myContents
tell property list item (aTrackId as string)
set myUrl to |Location| of (value as record)
set end of myUrls to myUrl
end tell
end tell
end repeat
end tell
end tell
end tell
end tell
end tell
set myIndex to 1
do shell script "mkdir -p ~/Desktop/itunes-playlist-export"
repeat with myUrl in myUrls
if myIndex < 10 then
set myIndex to "0" & myIndex
end if
set myUrl to myUrl as URL
set myPath to POSIX path of POSIX file myUrl
set myBasename to do shell script "basename " & quoted form of myPath & " | sed -e 's/^[ 0-9-]*//'"
set myDestination to (myIndex as string) & " " & myBasename
set cmd to "cp " & quoted form of myPath & " ~/Desktop/itunes-playlist-export/" & quoted form of myDestination
do shell script cmd
set myIndex to myIndex + 1
end repeat
end open
Comments
Posted by
Marc
on 16 Jun 2009 22:38
habi: good point, also a nice solution...
|



great script, but you could also have used itunesFS [1] together with macfuse [2], which makes all your iTunes playlists available as folders in Finder, with numbering and ready for copying to wherever you want.
[1]: http://www.mulle-kybernetik.com/software/iTunesFS/
[2]: http://code.google.com/p/macfuse/