Satimage Previous
HTML interfaces
Home Documentation Smile Custom GUI HTML interfaces  

You can make HTML interfaces to Smile as an alternative to GUI aqua dialogs. Such interfaces are regular HTML files eventually including or importing images, javascript, css, etc. Some examples are provided in the /Applications/Smile/Script examples/Smile examples/User Interface examples folder.

With the Smile Server license, you make such a HTML interface into a web application that all users in the Internet can run in their browser.

Editing HTML in Smile
In Smile, HTML files open in Unicode windows where you can edit the HTML source. Pressing ⌘R renders the HTML in a new window. Moreover, pressing ^⌘R checks the XML syntax and pressing ⌥⌘R checks the validity of the XML with respect to its DTD. Please read the documentation about Unicode window.
How to display HTML in Smile by script
The class of windows to display HTML in Smile is the web window. To load a HTML page (or a JPEG image, etc) set the web window's path name property to an alias or a string which makes a valid URL.
set w to make new web window with properties {path name:alias "...:index.html", script: alias "...:myScript.scpt"}
Alternately you can directly provide HTML source into the contained data property. This can be useful if you generate the HTML contents dynamically.
set w to make new web window
set contained data of w to "<html><header/><body>hello world</body></html>"
Calling Smile from JavaScript: the AS JavaScript object
The web window contains a special AS JavaScript object in order to communicate with Smile. This object has no property, but all its functions are interpeted as calls to some AppleScript handler. Example: suppose that you have defined an Applescript handler as:
on foo(s)
return 10
This handler may be in the context of Smile or in the script of the web window.
Now from JavaScript you call this handler with:
The parameters may be of type number, string, boolean, array or JSObject. The JavaScript object window is also valid and will result in an AppleScript reference to the web window containing the AS object.
Conversely number, string, boolean,array and record may be returned by called handler.
Calling JavaScript from Smile
  • The callJavaScript command tells the web window to execute a text script:
    callJavaScript w script "document.getElementById('x').value"
  • The above method may be awkward if you need to pass complex parameters to JavaScript. In this case, it may be easier (and more efficient) to use the callJavaScriptFunction command:
    callJavaScriptFunction w subroutine "SetArray" parameters {myHugeArray}
The JavaScript Console
For debugging purpose, you can also open a JavaScript console with the contextual menu.
A JavaScript console is associated to the web window and works like the AppleScript terminals: the Enter key execute the current selection or the current line.
Comparison between HTML and Aqua dialogs
  • Advantages of HTML interfaces
  • Such interfaces are recommended to people familiar with HTML/javascript development. They benefit from the dynamic layout of HTML rendering, the use of css, the powerfulness of javascript, etc.

    HTML browsing is often more suitable to multiple pages contents.

    HTML can be more easily generated, for example using XSLT.

    Such HTML interfaces can be ported to the web using Smile Server features.

  • Disadvantage of HTML interfaces
  • For simple cases, Aqua dialogs can be developed more quickly in Smile.

AppleScript and HTML : the old way
Smile claims to handle the URL scheme "smile".
The old method used this scheme and the open location AppleEvent to handle the communitions between the web window and AppleScript. This method is still valid but awkward.
Version française
Copyright ©2010 Paris, Satimage