Satimage Previous
Referring to an object
Home Documentation Smile Smile's objects Referring to an object  
With AppleScript, you can address elements of the application because AppleScript lets you handle references to objects.
  • The dictionary of Smile includes the application class. There is only one object of the application class: the application itself. The Elements entry in the application class shows the classes of objects that you can address directly, and how to access them (by name, by position or by id). For instance, the application class's Elements entry includes the graphic window class, thus the following are correct references (not necessarily valid references, maybe the object does not exist).
    set theWind to graphic window 1
    set theWind to graphic window "untitled"

    Other classes may contain elements according to what the dictionary states in the entry for that class. For instance, objects of the dialog class may contain objects of the dialog item class.
  • To refer to an object which is an element of another object, use the of preposition to walk the hierarchy, whose implicit root is the application itself:
    set theCurve to curve 3 of plot view "Temperatures" of theWind
    You use such a reference, for instance, to change some property of the object:
    set theCurve to curve 3 of plot view 1 of graphic window "untitled"
    set pattern style of theCurve to 8

    Obviously any class presented in the dictionary, except the application class, has to be declared as a possible element of at least one "container" class.
    Whenever no confusion may be possible, you can address an element with the generic term item, followed by the element's index. For instance, the two expressions below return the same object, provided the graphic window contains only plot views :
    set theCurve to curve 3 of plot view 1 of graphic window "untitled"
    set theCurve to item 3 of item 1 of graphic window "untitled"

    To refer to an object which is an element of another object, you can alternately use the generic item keyword.
    set theCurve to item 3 of item 1 of graphic window "untitled"
        -- curve id 56 of plot view id 7 of graphic window id 89
  • As you observe, various descriptors can refer to the same object.
    window 2
        -- text window id 1
    window "Worksheet"
        -- text window id 1

    Among those descriptions, the canonical one (the unique descriptor that Smile uses internally, that is returned when you evaluate a reference) is by id. The descriptors by id remain valid and uniquely defined all through the session.
  • The container property of any object refers to the object which contains it.
    dialog item 1 of dialog item 9 of dialog "Find"
        -- dialog item id 28 of dialog item id 27 of dialog id 14
    container of dialog item 1 of dialog item 9 of dialog "Find"
        -- dialog item id 27 of dialog id 14
    container of container of dialog item 1 of dialog item 9 of dialog "Find"
        -- dialog id 14
  • Smile objects have two other special properties, properties and whole.
    The properties property of an object returns a record that contains all the settings of the object.
    The whole property returns, in addition, the object's script and, when this makes sense, the list of the whole properties of its elements. These special properties are intended for saving or cloning objects.
Copyright ©2008 Paris, Satimage