When you want to access your file system on your Mac, you access the Finder. The Finder is an application that allows users to access their folders and files. With AppleScript, you can access your folders and files programmatically by bossing around the Finder. Let’s open up the Finder’s dictionary in Script Editor. Open Script Editor. From the File menu, select Open Dictionary…, then select Finder from the dialog box. Once you have the Finder’s dictionary open, select “Containers and files” from the leftmost column:

In the center column, you’ll see several terms preceded by a the letter “C” in a square. These items are containers. As you can imagine, these items contain other items. Click on the word “disk” in the middle column. In the rightmost column, you’ll see several terms preceded by the letter “E” in a square. These items are elements of the “disk” container. Elements make up the contents of a container. And this makes sense because in a disk you might find one or more folders. If you click on the “folder” container, you’ll see elements of folders such as a “file”. Again, this makes sense because folders often contain one or more files.
Look again at the “disk” container. In the bottom pane, AppleScript defines certain properties of every “disk” object:

These properties identify one “disk” object from another disk object. Properties of disk objects include “capacity”, “free space”, and “format”. Each disk object has different properties to distinguish them from other disk objects. Obviously, some properties of different objects will be the same.
Disk objects have additional properties that you can find by following the links in line 1. Let’s look closer at line 1 as shown in the image above. The line reads:
disk n [inh. container > item] : every disk
The first word identifies the selected item, which AppleScript helpfully describes as “every disk”. We’re concerned with the information between the brackets. The first term is “inh.” which is short for “inheritance”. What does this mean? Thankfully, inheritance here has nothing to do with the Rule Against Perpetuities, but it does have a similar meaning to inheritance that you learned in your Wills class in law school. Briefly, inheritance means that the object inherits the properties from the objects listed within the brackets. Here, disk objects inherit the properties from container objects which inherits properties from item objects. If you click on the blue links, the dictionary will change to that object. You can work your way up and down the inheritance chain. Click on the link to item. The first property listed is “name”, which tells us the name of the item, here, a disk. Let’s ask the Finder for the name of our first disk. (You may have more than one disk attached to your computer.) In Script Editor, type the following:
tell application "Finder"
get name of disk 1
end tell
In the Result pane, you should see the name of your hard drive. (Mine is “Macintosh HD”). So what did we do? We told the Finder to get the name property of the first disk object. Although we didn’t see the “name” property in the property definition for “disk”, AppleScript found it by looking up the inheritance chain until it found a “name” property, then returned the name to us. If we asked for a property that was not in the inheritance chain, then AppleScript would raise an error, which, of course, we would handle properly.
We’ll look at more containers and elements of the Finder in our next episode.
Leave a Reply