DekGenius.com
Team LiB   Previous Section   Next Section

Chapter 15. Mac OS 9 Finder Classes

The best way to script the Finder under Mac OS 9 is to get up close and personal with its object model. What is an object model? An object model is an abstract depiction of a software program (such as the Finder). This model, similar to an architectural model of a house or landscape design, conveys the program's behavior or what it is designed to do in the form of functions and commands, for example:

shut down

or:

get size of folder "giantFolder"

The object model also depicts the software units that comprise the software, along with the elements or properties that distinguish the Finder from other Mac software programs. The values of elements and properties differentiate one version of the Finder from another. You might recall from the brief Chapter 1, object discussion that an object has exactly one of its properties (e.g., the Finder has one name property and that is, as you might have guessed, "Finder"). A person object might have an age property. They can only have one age value at any given time, except for those of us in our forties who are fond of trying to recapture our twenties (we can have two ages at any given time, chronological and imagined). On the other hand, an object can have zero or more elements. For instance, the Finder has an item element, because the Finder usually works with numerous items during its computing session, such as disks, folders, and files. Figure 15-1 shows the Finder's object model, including its elements and properties.

Figure 15-1. Finder's object model
figs/ascr_1501.gif

If you have ever dealt with object-oriented software and design before, then you might have guessed that Finder elements and properties are associated with classes and objects too. An inheritance structure defines Finder elements. This structure is summarized in Figure 15-2.

The Finder objects, and their elements and/or properties, are listed in the Finder's dictionary window. You can display this window by choosing File:OpenDictionary... when you are in Script Editor, then selecting the Finder in the resulting dialog window.

The inheritance structure is like a family tree. At the top of this structure is the item. Most things that you refer to in scripts inherit from the item class and are therefore item objects, such as disks, files, and folders. An item has properties such as folder (the folder that contains the item), name (a string like "Myfolder"), size (the logical size in bytes of the item), and creation date (the date the item was first saved to the hard disk). Figure 15-2 shows a subset of the properties for each object beneath the object's name. Some of these objects, such as document file, a specialized subclass of file, do not have separate properties compared with their parent class.

Figure 15-2. Summary inheritance tree for various Finder objects
figs/ascr_1502.gif

If an object, such as a file, inherits from or is a child object of the item class, then it also has name, folder, size, and creation date properties. The container object also inherits from the item class; sharable container in turn inherits from the container class and adds some of its own file-sharing related properties such as owner and shared (a true/false value). Finally, the disk and folder objects are child objects of sharable container. They also inherit from the super class (container) of their own parent (sharable container), so they have the properties of the container class, such as entire contents. If you work your way up the inheritance tree, then you find that disks, files, and folders are also items, and in this case inherit all of the item's properties.

When using the Finder's make command to create new objects, you have to stick to specific, non-abstract classes such as files and folders. You cannot "make" a new sharable container or item, for instance. But you can get a list return value of all items or sharable containers with the following code phrases: tell app "Finder" to get sharable containers or get items. See Example 15-1.

For example, a disk has all of the properties of sharable container. Example 15-1 gets all of the sharable container-related properties of a disk for viewing in the Script Editor's Event Log (Chapter 2, describes the Event Log window). But a disk also has its own properties that another sharable container does not have, like such as space (the number of free bytes left on the disk) and ejectable (a true/false value for whether it can be ejected from the computer).

Example 15-1. A Disk's sharable-container Properties
tell application "Finder"
   (* use Event Log to view values *)
   set d to disk "HFSA2gig"
   d's owner
   d's group
   d's owner privileges
   d's group privileges
   d's guest privileges
   d's privileges inherited
   d's mounted
   d's exported
   d's shared
   d's protected
end tell
    Team LiB   Previous Section   Next Section