iTunes: Play Each Sample

This script uses GUI scripting to extract the text data from the search results pane in the iTunes browser window. The script will then play each sample in the list of found tracks.

[requires a fast Interent connection like DSL or Cable]

Enjoy!

Sal

try
	tell application "iTunes"
		activate
	end tell
	tell application "System Events"
		tell process "iTunes"
			click menu item "Select All" of menu "Edit" of menu bar 1
			delay 2
			click menu item "Copy" of menu "Edit" of menu bar 1
			delay 1
			click menu item "Select None" of menu "Edit" of menu bar 1
		end tell
	end tell
	set the track_list to the clipboard
	if the track_list is "" then error "Please copy the song list to the clipboard before running this script."
	tell application "iTunes"
		repeat with i from 1 to the count of paragraphs in the track_list
			set this_track to paragraph i of the track_list
			set x to the offset of "	" in this_track
			if x is not 0 then
				set AppleScript's text item delimiters to tab
				copy every text item of this_track to {track_title, track_duration, track_artist, track_album, track_price}
				set AppleScript's text item delimiters to ""
				display dialog "Playing: " & track_title giving up after 2
				play
				delay 30 -- connect to store
				repeat until player state is stopped
					delay 5
				end repeat
				next track
			end if
		end repeat
		display dialog "Playback complete." buttons {"OK"} default button 1 giving up after 3
	end tell
on error the error_message number the error_number
	if the error_number is not -128 then
		display dialog error_message buttons {"Cancel"} default button 1
	end if
end try