Adobe 27510753 Scripting Guide - Page 38
Adding the user interface
UPC - 718659445294
View all Adobe 27510753 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 38 highlights
30 Getting Started with InDesign Scripting Adobe InDesign CS2 Scripting Guide Like any other InDesign scripting object, each part of a dialog box has its own properties. A checkbox control, for example, has a property for its text ("static label") and another property for its state ("checked state"). The dropdown control has a property for setting the list of options that appears on the control's menu ("string list"). To use a dialog box in your script, you create the dialog box object, populate it with various controls, display the dialog box, and then gather values from the dialog box controls to use in your script. Dialog boxes remain in InDesign's memory until they are destroyed. This means that you can keep a dialog box in memory and have data stored in its properties used by multiple scripts, but it also means that the dialog boxes take up memory and should be disposed of when they are not in use. In general, you should destroy the dialog box object before your script finishes execution. Adding the user interface In this example, we'll add a simple user interface to our Hello World script. The options in the dialog box will provide a way for you to specify the example text (we assume that you're tired of the phrase "Hello World" by now) and change the point size of the text. These examples also use a handler (AppleScript), or function (VBScript, JavaScript), to get the live area of the current page ("myGetBounds"). AppleScript 1. Enter the following AppleScript in your script editor. --Simple User Interface Example tell application "Adobe InDesign CS2" activate set myDocument to make document set myDialog to make dialog tell myDialog set name to "Simple User Interface Example Script" set myDialogColumn to make dialog column tell myDialogColumn --Create a text entry field. set myTextEditField to make text editbox with properties ¬ {edit contents:"Hello World!", min width:180} --Create a number (real) entry field. set myPointSizeField to make real editbox with properties {edit contents:"72"} end tell show --Get the settings from the dialog box. --Get the point size from the point size field. set myPointSize to edit contents of myPointSizeField as real --Get the example text from the text edit field. set myString to edit contents of myTextEditField --Remove the dialog box from memory. destroy myDialog end tell tell page 1 of myDocument --Create a text frame. set myTextFrame to make text frame set geometric bounds of myTextFrame to my myGetBounds(myDocument, page 1 of myDocument) --Apply the settings from the dialog box to the text frame. set contents of myTextFrame to myString --Set the point size of the text in the text frame. set point size of text 1 of myTextFrame to myPointSize end tell end tell on myGetBounds(myDocument, myPage) tell application "Adobe InDesign CS2" set myPageHeight to page height of document preferences of myDocument