Sometimes a lone Apple event like quit or activate will do the trick in a script. At other times, Apple events have to specify Apple event parameters. These are the data the receiver of the Apple event needs to carry out the Apple event’s instructions. For instance, if the Example 1-3 script did not include the parameter:
file "mydocument"
then the OS 9 Finder would return an error, because its open Apple event requires a reference to the object(s) to open.
tell application "Finder" (*open is the command; file "mydocument" is the parameter *) open file "mydocument" end tell
Examples in this book will usually include comments explaining code elements. Comment characters in AppleScript are two hyphens (—) for single-line comments and parentheses containing asterisk characters (* *) for multi-line or single-line comments.
Figure 1-5 illustrates the Finder’s open Apple event with the reference to the mydocument file.
Apple event parameters can include standard data types (e.g.,
integer
or string
) or
references to Apple event objects, such as a document file. Apple
event objects are the items or
“nouns” (e.g., a file, a folder, a
database record) that some scripts interact with. See
Section 1.2.6 for further explanation on handling objects in your scripts.
An Apple event can have more than one required or optional parameter.
In another example, if you want your script to tell FileMaker Pro to
create a new row in a database, then create is
the Apple event (followed by the required keyword
new
). The create Apple event
requires a parameter such as a record
object (as in a database record or
row). Otherwise, how would the database program
know what you wanted to create?
The code in Example 1-4 opens a database file and then creates a new record with empty fields.
tell application "FileMaker Pro" activate --brings the target application to the front open file "startupdisk:fm databases:myDB.fm4" create new record - "record" is the parameter end tell
Example 1-4 could use the create
command’s optional with data
parameter to fill the new row
with data, thus creating a complete database record.