Satimage Previous
HTML interfaces: the old way
Home Documentation Smile Custom GUI HTML interfaces HTML interfaces: the old way  

Here is the old documentation about HTML interfaces.
These methods are still valid but deprecated.

How to communicate with AppleScript from an HTML page
HTML can interact with Smile with:
  • a HTML link like:
    <a href="smile://myfunction?mytext">click here</a>
  • an HTML form element like:
    <form method="get" action="smile://myfunction" enctype="application/x-www-form-urlencoded" accept-charset="utf-8">
    <input name="refresh" type="submit" value="OK" />

    Such a form can contain any number of form inputs: elements input, select, textarea, etc.

In both cases the URL scheme must be smile, not http.

The host name of the URL (myfunction in the examples above) defines which AppleScript handler is called: in these examples, a handler named openlocation_myfunction(x, w) will be called when the user click the link or a submit button.
The parameter w is a reference to the web window issuing the request. If this request comes from an external browser, w is set to 0.
The parameter x is the whole URL, for instance "smile://myfunction?mytext" or "smile://myfunction?refresh=OK".

The AppleScript handler openlocation_myfunction(x, w) can be defined either in the Smile context, or in the script of the web window.
To include a handler into Smile's context, you can:

  • compile it in an AppleScript terminal,
  • use the add library command which includes a file or a string,
  • use an AppleScript library as explained in the page about Using AppleScript libraries.

When the URL comes from an HTML form, you can use the parseFormURL command to translate it into a plist provided as a Unicode string, that you can easily use with the property list suite of XMLLib.osax.

on openlocation_myfunction(x, w)
    msg("url: " & x)
    set p to PlistOpen (parseFormURL x)
    msg(PlistGet p key "refresh")
    PlistClose p
end openlocation_myfunction
-- OK

NB: the pageloaded event is sent to the script of a web window when its load is complete. This is the first time to call safely a javascript in a new web window (or in a window modified with reloadURL or set contained data or set path name).

Communicating from AppleScript to HTML
The AppleScript handler called from the HTML may change the HTML contents. There are several ways to do that:
  • You can change the HTML source and tell the web window to reload, using the reloadURL command.
  • You can load another HTML file by changing the path name property of the web window.
  • You can set the HTML contents of a web window dynamically by settings its contained data property to a string containing the HTML source.
  • You can run a javascript script in the web window using the callJavaScript command or call a javascript function with the callJavaScriptFunction command (described in Smile's dictionary).
Version française
Copyright ©2010 Paris, Satimage