dougscripts.com

Working With Playlists 1 2 3 

Here's a down and dirty cheat sheet on how to access and refer to many of the various track and playlist objects in iTunes. These are by no means written in stone. If you can think of any other vital snippets, let me know.

 

To reference one of the Master Libraries, use its special kind property in a whose clause (this will also prevent ambiguous results from localization differences).

-- get "Music" playlist
tell application "iTunes"
	set music_playlist to (get some playlist whose special kind is Music)
end tell

To reference the playlist selected in the Source pane:

tell application "iTunes"
	set myPlaylist to view of front window
end tell

To reference the playlist of the currently playing track:

tell application "iTunes"
	if player state is playing then
		set myPlaylist to current playlist
	end if
end tell

To reference a playlist by name:

tell application "iTunes"
	set myPlaylist to playlist "Mom's Favorites"
end tell

To get a list of references to all playlists:

tell application "iTunes"
	set everyPlaylist to (get every playlist)
end tell

-- to get the name of every playlist:
tell application "iTunes"
	set everyPlaylistName to (get name of every playlist)
end tell

To reference the main radio tuner playlist:

tell application "iTunes"
	repeat with i from 1 to the count of sources
		if kind of source i is radio tuner then
			set myPlaylist to radio tuner playlist 1 of source i
			exit repeat -- optional
		end if
	end repeat
end tell

-- or
tell application "iTunes"
	set myPlaylist to radio tuner playlist 1 of (some source whose kind is radio tuner)
end tell

To reference an audio CD playlist:

tell application "iTunes"
	set myCD to some source whose kind is audio CD
end tell

-- and thus...

tell application "iTunes"
	set myCD to some source whose kind is audio CD
	set CDname to myCD's name
	set evCDtrack to (get name of every track of playlist 1 of myCD)
end tell

To reference the main Library of iPod:

tell application "iTunes"
	set myPod to some source whose kind is iPod
	set mainPodPlaylist to library playlist 1 of myPod
end tell

To reference every playlist of iPod:

tell application "iTunes"
	set myPod to some source whose kind is iPod
	set evPodPlaylist to (get every playlist of myPod)
end tell

< prev | 1 2 3 | next >
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.