frontpage : tips & info : here
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