coercions.htmlTEXTVIZFG ɴ  Smile coercions

Smile coercions

Smile provides several coercions. To use them, your script must be running under Smile, or in a 'tell application "Smile"' wrapper.

Coercions for scripts

You can make a script into a string, and a string into a script. This allows for dynamical script editing (in other terms, making or changing a script by script).
----------------------------
set script of window 1 to "-- aaargh !"
----------------------------

This simple example replaces the object script of the active window.

----------------------------
display dialog (script of window 1 as text)
----------------------------

This will display the script of the active window in a dialog box (provided it is not too long).

Coercions for files

Smile coerces aliases to strings and to file references.

Turning things into string

The 'display' command, part of Smile's dictionary, coerces any arbitrary reference to text. For instance, you can turn a list into its usual string representation :
----------------------------
display {2 + 2 = 4} --> "{true}"
----------------------------

If 'display' does not seem to be able to coerce some expression into text, try making the expression a list's item (this powerful trick has been pointed out by J-P Pellet).
----------------------------
display ({application "Finder"})
----------------------------

When working in Smile, you can get the four-character codes of the object classes.
----------------------------
class of window 1 as text --> "cwtx"
----------------------------

For properties, use the 'as raw code' coercion.
----------------------------
bounds as raw code as text --> "pbnd"
----------------------------

Coercions and objects

Smile can make any of its objects into a record, which contains all its useful properties, except its script.
----------------------------
window 1 as record
----------------------------

You get a complete record, containing all the data needed to clone the object, by using the command 'whole'. (Use this example with care).
----------------------------
make basic object with properties (get whole of window 1):
----------------------------

Smile can make any property of 'every ...' into a list. The plural can be used instead of the 'every' keyword.
----------------------------
windows as list --> returns the list of the opened windows
----------------------------

----------------------------
name of windows --> returns the list of the names of the opened windows
----------------------------

 _@N0N(Re B&W Video In ?.2IFCOMMMFCOMMManh[АJo\Oo/ N0XO J$_Nu/ $o g Ah$Bg/ N Jo\Oo/ N0XO J$_Nu/ $o g A$Bg/ N8Jo\Oo/ N0XO J$_Nu/ $o g g    k   k"  5  kh    k7  P  k`    k  *  k.  c  kg    k            k  :  k>  m  kq    k    k;  R  kb    k    k    k    k    k  0  k\    k  0  k4  b  kf    k    k    k  A  k E  e  k m   k   k   k   "  k `  y  k   k    k "  8  k <  \  k d   k    k   X  k \  |  k   k    k   _  k c   k   k   k  !  kE  ~selelist long long pbndlist8long'long8longlongBDrwfalspvistrueWIDLfalsICFFlongrSiDlongptxfTEXTGenevaptpslong Rectlist8longlonglonglongWTBHlongRqULlongLWdtlongBrWdlongAuAdfalsTbSzlong  _@=ZstylSOUP&reco2Acwtx