This article and the attached script briefly demonstrate how to achieve a handy Unicode Character Infos box in InDesign using various Extendables' shortcuts and modules. Although the framework isn't yet feature-complete, it already offers one of the most wanted ExtendScript add-on: a cool HTTP library that hides all that boring Socket stuff and allows you to perform HTTP requests without effort.

So, what our sample script does is that it queries a Web service and displays a number of Unicode details about any single character that the user selects in the active Document:

Unicode Character Infos. Just select a character in InDesign and run the script!

You can download CharInfos.jsx at the bottom of this page. Don't forget you need to install Extendables too! (See the Extendables' documentation for further details.)

Quick Installation

Extendables is an open source project maintained at GitHub by Stijn Debrouwere:
http://stdbrouw.github.com/Extendables/.

Download the most recent release and unzip the entire package within your scripts folder, usually somewhere like Scripts Panel/extendables/. In fact you can drop the Extendables' package anywhere, provided that your script properly points out to the main extendables.jsx file using a valid relative path in the #include directive (thanks to Stijn who immediately fixed an issue in this regard):

// At the beginning of your script:
#include 'relative/path/to/extendables.jsx'
 
// Your script
. . .
 

CharInfos.jsx has the following #include directive —which you may need to adjust according to your own configuration:

// We here assume that the client script is located in
// the parent folder of the 'extendables' folder:
#include 'extendables/extendables.jsx'
. . .
 

Extendables Main Bricks

The figure below shows the general structure of the framework and its most important components:

Main Extendables' bricks

To get started, just remember that Extendables simplifies ExtendScript coding in two main ways:

• It adds functionalities to the core and DOM objects by feeding their prototype. (Explore the patches folder to get more details; See also the “Javascript and DOM enhancements” overview.)

• It offers specialized modules that wrap complex features through simple interfaces, such as HTTP requests (http module) or ScriptUI stuff (ui module). (Explore the core-packages folder to see the earliest libraries; see also the “Packages” overview.)

Our Sample Script

CharInfos.jsx uses the http and the ui modules, and various handy object helpers provided by Extendables, like String.format(), or Object.keys(). I won't discuss here the minor details of the script, which by the way implements a raw HTML parser through XML. Broadly, we send an HTTP request to www.fileformat.info/info/unicode/... by formatting a specific URL which contains a character codepoint. The server then returns the HTML response (see an example of response by clicking here: www.fileformat.info/info/unicode/char/01FD/). Of course the InDesign user will not see the web page, we don't need it to be rendered in a browser. Our goal is just to grab the informations it contains.

Technically, this is the http module that manages the web request, while our code extracts data of interest. Thus, here is the skin-deep structure of the process:

#include 'extendables/extendables.jsx'
 
// Tell Extendables we gonna use
// the 'http' and the 'ui' modules:
var http = require('http');
var ui = require('ui');
 
function parseHTML(/*str*/ htmlBody)
{
    // Our HTML parser
}
 
function getUnicodeCharInfos(/*str*/ charStr)
{
    // based on charStr Unicode value:
    var url = /* format the search URL */
 
    // Sends the HTTP request to the server:
    var response = http.get(url);
 
    // Calls the parser
    var infos = parseHTML(response.body);
 
    return infos;
}
 
function displayInfos(...)
{
    // Uses the ui module to
    // create a nice ScriptUI dialog box
}
 
function main()
{
    car = /*getSelectedCharacter*/
 
    infos = getUnicodeCharInfos(car);
 
    displayInfos(infos);
}
 
main();
 

That's it!

To go further in understanding and implementing these steps, I let you examine the (generously commented) code: