Have you ever wanted to copy some songs of your iTunes library onto a USB key?

Here is a little script to do just that. Here is how to do it :

  1. Gather all the songs you want to export in a playlist
  2. Launch the following script with Script Editor for example.

tell application "iTunes"
	-- Asks the user to select a playlist to copy
	set itunesPlaylists to (get name of playlists)
	set selectedPlaylist to {choose from list itunesPlaylists}
	
	-- Get every track in the selected playlist
	set itunesFiles to (every file track of playlist (item 1 of (item 1 of selectedPlaylist)))
	
	-- Asks the user to select the destination folder (where the files will be copied)
	set destinationPath to (choose folder with prompt "Destination folder :")
	
	-- Creates a list of the files' path
	set pathsList to {}
	repeat with iTunesFile in itunesFiles
		set loc to (get location of iTunesFile as text)
		set pathsList to pathsList end repeat
	
	-- Copies the files into the destination folder
	repeat with finderPath in pathsList
		my duplicateSong(finderPath, destinationPath)
	end repeat
end tell

-- Copies iTunesFile into destination folder
on duplicateSong(iTunesFile, destination)
	tell application "Finder"
		set n to destination as alias
		duplicate iTunesFile to n
	end tell
end duplicateSong

Grégoire Willmann

French entrepreneur

gwillmann lejonqc


Published