AppleScript Changes in iTunes 4

iTunes 4 was released on April 28 2003 as part of Apple's "music to your ears" announcement for the iTunes Music Store. Also announced were new iPod models and QuickTime 6.2.


Note: iTunes 4.0.1 was released on May 27, 2003. One notable change: internet playlist sharing is now disabled, although LAN sharing is still intact. Where applicable, information is updated below for iTunes version 4.0.1.


iTunes 4 has made network music sharing possible (and somewhat legal) via Rendezvous support and online music purchasing legitimate and easy. Accompanying these innovations are these residual benefits: iTunes 4 has introduced the ability to associate "artwork" with audio tracks; and using QuickTime 6.2 you can rip AAC audio files, a new, compressed format that provides a higher sonic quality at smaller bit rates.

Access to shared libraries via AppleScript is off limits, let me get that out of the way right up front. There is no way to access any information about tracks in a Shared Music playlist. Not no way not no how. Ditto iTunes Music Store.

Update: version 4.0.1 will allow you to glean various track tags of shared tracks. Since you can no longer access shared internet tracks, Apple probably considered this safe enough.


iTunes 4 adds the ability to assign "artwork" to a track. You can add artwork directly in a track's get info window—which now presents four panels: "Summary", "Info", "Options", and "Artwork", formerly just "Info", "Tags", and "Options"; same order of panels, the panels are just renamed. The "Summary" panel is beefed up with Album artwork space.

Anyway, to accomodate artwork, there is a new "artwork" class. A track can contain "artworks" and you can refer to an individual "artwork" by index or by its position (first, front, last, etctera). The actual picture data is in the artwork property "data". This is a bit of the script Selected Artwork to All In Playlist:

tell application "iTunes"
	set myP to view of front window
	if selection exists then
		set c to (item 1 of index of selection)
		tell myP
			if artworks of track c exists then
				set theArt to front artwork of track c
				set pic to (data of theArt) as picture -- this is it
				repeat with i from 1 to count of tracks
					tell track i
						set data of front artwork to pic
					end tell
				end repeat
			end if
		end tell
	end if
end tell

I haven't done much more with it than that. Hopefully it will spawn more artwork scripts.

Update: using version 4.0.1, I was able to choose a .pict file—which I had previously exported via Preview—and add it to a selected track, like so:

set theImage to read (choose file) as picture
tell application "iTunes"
	set theT to item 1 of selection
	tell theT
		set data of artwork 1 to theImage
	end tell
end tell

New track property

The track property bpm (beats per minute) has been added. You access it like any other track property. You can get it and set it with an integer:

tell application "iTunes"
	set myTrack to (track 1 of view of front window)
	set myTrack's bpm to 120
	-- or
	set myTrack to (track 2 of view of front window)
	if myTrack's bpm is greater than 120 then stop
end tell

I am not sure, however, where you get the BPM info, whether it is available via CDDB or what. Still, for DJs, a pretty helpful tag.

New Class: shared track

Version 4.0.1 tooketh away internet sharing, but lefteth network sharing via Rendezvous. We can now safely gather tag data on shared tracks from shared playlists via the shared track class (there is also an "s track" class in the dictionary, but this is for device tracks). Shared track has most of the properties of the track class except, of course, location ("I'm shocked...shocked to find that file sharing is going on in here!") Properties of shared track are read-only, so you can't change any shared track info. Quick example: if you select a shared track and run this:

tell application "iTunes"
end tell will get something like this: {shared track id 5946 of library playlist id 4872 of source id 4871 of application "iTunes"}. You can also select the shared playlist and run something as generic as this:

tell application "iTunes"
	set thePlaylist to view of front window
	tell thePlaylist
		get name of every track
	end tell
end tell

...and the result will be as expected: you get the shared track names in the selected playlist. This also works when current track is a shared track. These properties are available from shared track: index, name, album, artist, bpm, comment, compilation, composer, disc count, disc number, enabled, EQ, finish, genre, rating, start, track count, track number, volume adjustment, and year; again, no location property.

New Encoder

If you have access to QuickTime 6.2 or better you may use The Fourth Encoder. "AAC Encoder" will be an option under your Importing Preferences. "AAC Encoder" is the name of the encoder, so you can:

set current encoder to encoder "AAC Encoder"
Site contents © 2001 - 2024 (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.