References to objects

    A command requires at least one object. If you don't specify an object, AppleScript uses a default object, which is usually the active application. You can specify the default object for commands by using a Tell control statement.

    To identify the objects of a command, you use a reference. The following phrase is a reference:

    the comment of file "Picture 1" of desktop

    A reference provides this information to identify an object:
    its class
    its container
    information that identifies a particular object or objects

    In the example, the class of the object is "comment" while the container is a series of containers: a file located on the desktop. The name "Picture 1" identifies a specific file.

    AppleScript provides several ways to reference objects. Here are some of the forms you can use.

    Name:
    Specifies an object by name.

    close document "Report"

    Index:
    Specifies an object by its position in a container.

    word 2 of paragraph 3

    Positive numbers indicate the position from the beginning of the container; negative numbers from the end.

    You can use keywords such as first, second, and third, or write the numbers like this: 1st, 2nd, 3rd.

    second word of third paragraph

    2nd word of 3rd paragraph

    You can use these keywords: last, front, back.

    last word of third paragraph

    Property:
    Specifies a property of an application object, script object, record, or date.

    name of front window

    ID:
    Specifies an object by its ID property.

    id of disk "Hard Disk"

    Every:
    Specifies every object of a class in a container.

    every word of "That's all folks."

    You can use the plural form of the name instead:

    words of "That's all folks."

    The resulting value of this reference is a list of the words.

    Filter:
    Specifies all objects in a container that match one or more conditions using either "whose" or "where."

    every file in control panels folder whose file type is "APPL"

    The part beginning with "whose" defines the condition. This is a Boolean expression that is either true or false.

    If nothing matches the condition, the application returns an error message unless you use the Every reference, in which case the application returns an empty list.

    Range:
    Specifies a series of objects of the same class in the same container.

    words 1 thru 4 of "We're all in this together"

    text from word 1 to word 4 of "We're all in this together"

 


Table of contents