// Dialog: A dialog remains visible as long as you interact with it, and while it is visible you can’t do anything else in InDesign.
var myWindow = new Window ("dialog", "Form");
myWindow.show ( );
// Palette: Palette is displayed on the screen you can continue to work in InDesign.
var myWindow = new Window ("palette", "Form");
myWindow.show ( );
// View Orientation
myWindow.orientation = "row"; // Window's default orientation is column
// Align
myWindow.alignChildren = "top";
// Groups and Panels
we can group items together using the ScriptUI items group and panel. These two function the same in that they group items together, but differ in two ways: panels have a border, groups don't; and the default orientation of a group is row, that of a panel, column. Groups (and panels) are good layout tools when you script windows.
Group
var myInputGroup = myWindow.add ("group");
myInputGroup.add ("statictext", undefined, "Name:");
myInputGroup.alignment = "right"; //aligned the group to the right of the window using alignment
// StaticText / Label
var myMessage = myWindow.add ("statictext", undefined, "Hello, world!");
or
var myMessage = myWindow.add ("statictext");myMessage.text = "Hello, world!";
myText.characters = 30; //set the width of an edittext control using its characters property
myText.active = true; //edit field were activated when the window is displayed so that the user needn't place the cursor there.
// EditText / Inputbox
var myText = myWindow.add ("edittext");
or
var myText = myWindow.add ("edittext", undefined, "John");
// Button
myWindow.add ("button", undefined, "OK");
//How to deal with the user's input and how to use that input in the rest of the script. In this example, two things can happen: the user clicks OK (which in this script corresponds to pressing Enter) or they can click
Cancel (which is the equivalent of pressing Escape). The window's behaviour is this: if the user presses OK, the line myWindow.show ( ) returns 1, if they press Esc, that line returns 2. We capture this as follows:
if (myWindow.show () == 1)
var myName = myText.text;
else
exit ();
Example:
var myName = myInput ();
// rest of the script
function myInput ()
{
var myWindow = new Window ("dialog", "Form");
var myInputGroup = myWindow.add ("group");
myInputGroup.add ("statictext", undefined, "Name:");
var myText = myInputGroup.add ("edittext", undefined, "John");
myText.characters = 20;
myText.active = true;
var myButtonGroup = myWindow.add ("group");
myButtonGroup.alignment = "right";
myButtonGroup.add ("button", undefined, "OK");
myButtonGroup.add ("button", undefined, "Cancel");
if (myWindow.show () == 1)
return myText.text;
else
exit ();
}