Two other very important characteristics of Apple event objects are elements and properties. The class that these objects are based on defines the object’s elements and properties. An object has zero or more of its defined elements, and exactly one each of its properties.
For example, SoundJam™ MP, a digital music player
and encoder, defines a playlist window
class.
These objects are windows that contain lists of audio tracks that can
play on the computer. Figure 1-6 shows the
definition of the playlist window
class from
SoundJam’s dictionary. (Chapter 2
explains a
program’s dictionary, which can be viewed by using
Script Editor’s File → Open
Dictionary menu command.) A playlist window
object
has three elements: track
, file track
, and URL track
. Further,
playlist window
s have a modified property (a
true
or false
value depending
on whether the window was modified since it was last saved).
playlist window
s also inherit several properties
from SoundJam™ MP’s
window
class. So a playlist window
object can contain zero or more
“track” elements, but it only has
exactly one “modified” property
value.
Rest assured that it is easy to grab the values of elements and properties in AppleScript. You can use syntax such as:
tell app "SoundJam™ MP" to get first file track of first playlist window
This code sends SoundJam™ a get Apple event requesting a reference to an element, such as the first file track (an MP3 audio file) in the foremost playlist window that you see when SoundJam™ MP is open. The return value looks like:
'file track id 4 of playlist window id 5 of application "SoundJam™ MP"'
Once your script gets a reference to a track, it can then command SoundJam™ MP to play it with (you guessed it) the play Apple event that SoundJam™ MP defines.
Our introduction to Apple events concludes with a description of the
all-important application
class, which is the
“king of the objects” in a
scriptable program. The program that you script, such as application
“SoundJam™ MP,” is
actually an object itself, an
“instance” of
the SoundJam™ MP
application
class.