iTunes export playlist text

Here’s a working script which exports track number, track name, artist and duration to a tab-delimited text file. This is handy for printing cd covers if the built-in iTunes templates drive you crazy by truncating text.

QUESTION: I got it to work stepping thru every user playlist and creating a text file for each; but how do I make it export just a selected playlist? “Current playlist” doesn’t work as I expected.

tell application "iTunes"
	
	set thetable to {}
	set mylists to (every user playlist whose special kind = none and smart = false and size > 0)
	repeat with thislist in mylists
		
		set theList to (name of thislist & return)
		
		repeat with theTrack in (tracks of thislist)
			set theList to theList & (track number of theTrack) & tab & (name of theTrack) & tab & (artist of theTrack) & tab & (time of theTrack) & return
		end repeat
		tell application "TextEdit"
			tell (make new document)
				set every text of it to (theList as string)
			end tell
		end tell
	end repeat
end tell

Model: Intel iMac
AppleScript: 1.10.7
Browser: Firefox 2.0.0.7
Operating System: Mac OS X (10.4)

Hi,

you can get the selected playlist with


tell application "iTunes"
	if selection is {} then
		set currentPlaylist to view of browser window 1
	end if
end tell

btw: iTunes’ export function does actually the same as your script. It creates a text file with all data
of the tracks of the selected playlist. The difference is, your script exports only a few parameters