What Is Scripting Like?
Scripting represents a conversation between you and an application, its documents, and the objects inside those documents. Via the script, you ask questions, issue commands, and decide on courses of action. As objects, the application and its components respond to your questions and commands. Scripting involves asking, thinking, and telling—pretty much what humans are capable of on a good day. Although scripting may appear cryptic at first glance, when you dig a little deeper you'll find that it's actually quite human-like, replicating human actions and at least some human thinking.
When you boil it down, scripts spend a lot of time directing commands to particular objects, which they identify via their unique addresses. To understand how this works, let's consider your own mailing address, which (assuming you live in the United States) includes the following:
- Your Name
- House Number, Street
- City, State, Zip
If you were to state your mailing address in a way that made sense to a computer, it would appear as follows: State > City > Zip > Street > House Number > Your Name. In other words, you are in the house; the house is on a street; the street falls within a Zip code; the Zip code exists within a city; and the city is located within a state.
Now consider how a script identifies an object: A circle resides in a document, and the document itself is "in" an application. Thus, the circle's address might appear as follows: Application > Document > Circle. This concept is also known as object containment: The circle is contained within the document, and the document is contained within the application. By tracing the object containment hierarchy, you can arrive at an object's address.
Properties—which for a person might be things like height, language, hair color, and shoe size—represent another important concept in scripting. Assuming I could change the aforementioned human properties with scripting, I might phrase a command like this: Set the height of person 1 of house 2 to 5'3". Or I might use the following: Change the location of person 1 of house 2 from kitchen to garage. The same principle can be applied to change the properties of Creative Suite objects (all objects have properties). Circles have heights and widths, fill and stroke colors, locations, and so on—all properties that you can change via scripting.
When you combine these two concepts—addresses and properties—you get what is called the object model; each application has its own custom object model. Much of what scripting entails, frankly, is using the object model to figure out how to talk to an object—a process that often takes the form of guessing and testing.