dougscripts.com

Working With Playlists 1 2 3 

 

Work with every track of a playlist selected in the Source pane

The playlist classes share several of the same properties. With that in mind, the myPlaylist variable in the example below could be a reference to any class of playlist.

tell application "iTunes"
	set myPlaylist to view of front window -- selected playlist
	repeat with aTrack in (get every track of myPlaylist)
		-- do something
	end repeat
end tell

Work with selected tracks of a playlist selected in the Source pane

tell application "iTunes"
	set myPlaylist to view of front window
	if selection is not {} then -- if there is a selection
		set fixed indexing to true
		repeat with aTrack in selection
			-- do something with aTrack, for example:
			log (get name of aTrack)
		end repeat
	end if
end tell

Usually, I'll use a routine that detects whether or not there is a selection to decide which tracks to use. If there are no selected tracks then the script assumes all the tracks of the selected playlist are wanted:

tell application "iTunes"
	set myPlaylist to view of front window
	if selection is not {} then -- if there is a selection
		set selectedTracks to selection
	else -- use every track
		set selectedTracks to every track of myPlaylist
	end if
	repeat with aTrack in selectedTracks
		-- do something with aTrack, for example:
		log (get name of aTrack)
	end repeat
end tell

Access URL tracks displayed in browser window

When the main radio tuner playlist is selected in the Source pane, this is how to access URL tracks that are visible; ie, a "folder" like "70s Pop" or "Electronica" is expanded. The example below gets the name of every URL track.

tell application "iTunes"
	set myRadioPlaylist to radio tuner playlist 1 of (first source whose kind is radio tuner)
	
	tell myRadioPlaylist
		if (count of URL tracks) is not 0 then
			set URLnames to name of every URL track
		else
			display dialog "No URL tracks are visible."
		end if
	end tell
end tell

more to come

< prev | 1 2 3 
Site contents © 2001 - 2022 (that's right: 2001) Doug Adams and weblished by Doug Adams. Contact support AT dougscripts DOT com. About.
All rights reserved. Privacy.
AppleScript, iTunes, iPod, iPad, and iPhone are registered trademarks of Apple Inc. This site has no direct affiliation with Apple, Inc.
The one who says "it cannot be done" should not be interrupting the one who is doing it.