objectscript.htmlTEXTVIZF oDDC Object scripts

Object scripts

Getting started with object scripts - Editing an object script

Smile is attachable. It allows scripts to be attached to any of its objects. An object script handles calls, some of which are automatically issued by Smile. For instance, when an object is created, its script receives automatically from Smile the message 'prepare theObject' (where 'theObject' contains a reference to the new object). The script can handle this call by a 'on prepare theObject' handler.

To view / edit the object script of a visible object (such as a button or a window),   -click its contents.

To close / save an object script use the corresponding items of the 'File' menu.
The object script of a text or script window, (and the object scripts of the objects that it may contain), is saved when you save the window to disk. This is also the case for custom dialogs .

Using the object scripts - 'continue' - 'container'

Two types of handlers can be installed in an object script : handlers for the AppleEvents sent by Smile, and your own AppleScript subroutine handlers.
On various occasions of the life of an object, Smile sends to it (that is, to its script) a message. Examples are : the 'prepare' message sent on creating the object, and the 'delete' message sent when it is suppressed.
Check the dictionary of Smile for the AppleEvents sent automatically by Smile ( Guide to Smile dictionary ). The AppleEvents which may be handled in object scripts are the 6 first verbs of the Smile Suite. 'idle' can also be handled.

The 'continue' AppleScript command is used to invoke a handler in a parent of the current script or in Smile itself. This is specially needed when you install a handler for a standard AppleEvent which needs to be finally handled by the core of Smile, such as 'save' or 'close'.
The 'container' property exists for each object script and refers to the object which owns the script.

The handlers contained in an object script can be called from anywhere. The calls to AppleScript subroutines must be encapsulated in a 'tell' statement, where the direct object is a reference to the owner of the script.
You refer to the direct object through the special variable 'it':
----------------------------
tell window 1 to AddOne(it's name)
----------------------------

The calls to AppleEvent handlers having an object specifier as the direct parameter are interpreted by Smile and automatically redirected to [the script of] the direct parameter. Thus if you write :
----------------------------
close window "foobar" saving ask

----------------------------
the 'close' event will normally be sent to window "foobar".
But if the caller script already defines a 'close' handler, you must write :
----------------------------
tell window "foobar" to close it saving ask
----------------------------

to send 'close' to [the script of] window "foobar", otherwise AppleScript will attempt to run the local 'close' handler.

Making scripts by script

Each object of Smile has elements and properties. One of the object's properties is its 'script': its object script . You can dynamically attach scripts to objects with a script. Below is an example of an attachment on the fly.
----------------------------
set script of window 1 to "property theList:{}
on AddOne(theMan)
copy theMan to end of theList
end AddOne"
----------------------------

To edit the object script of invisible objects (such as Smile for instance), use the 'EditObjectScript' routine (see Routines ).
----------------------------
EditObjectScript(current application)
----------------------------

  _ UCamras FireWire.FCOMMManj"w"`PoPm UCastles still unreachable.FCOMMManh"}"ᴩGm    k   k!  3  k    k    k          $  k9  >  kZ  _  kf    k    k            k  W  k  B  kF  %  k)  |        Y  k a  z  k ~   k   k    k   <  k @  f  k j   k  a  k e   k   k    k  f  kj    k    k  !  k%  E  kM    k  1  kH          k  ko    k    k    k  3  k7  K  kO  o  kw      '  +  1  k5  U  kY    k    k  ~selelist longjlongjpbndlist8long!long4long"longBDrwfalspvistrueWIDLfalsICFFlongrSiDlongptxfTEXTGenevaptpslong Rectlist8longlonglonglongWTBHlongRqULlongLWdtlongBrWdlongAuAdfalsTbSzlong   _@6ZZstylSOUP&reco2Adcwtx