Working with ScriptUI. Adobe InDesign CS6
விளம்பரம்
விளம்பரம்
C HAPTER 7: User Interfaces Working with ScriptUI 136 if selected button of myParagraphAlignmentGroup is 0 then set myParagraphAlignment to left align else if selected button of myParagraphAlignmentGroup is 1 then set myParagraphAlignment to center align else set myParagraphAlignment to right align end if
--Remove the dialog box from memory.
destroy myDialog my myMakeDocument(myPointSize, myString, myParagraphAlignment, myVerticalJustification) else destroy myDialog end if end tell
Here is the myMakeDocument handler referred to in the above fragment: on myMakeDocument(myPointSize, myString, myParagraphAlignment, myVerticalJustification) tell application "Adobe InDesign CS6" set myDocument to make document tell view preferences of myDocument end tell set myPage to page 1 of myDocument tell myPage set myTextFrame to make text frame set geometric bounds of myTextFrame to my myGetBounds(myDocument, myPage)
--Apply the settings from the dialog box to the text frame.
set contents of myTextFrame to myString
--Apply the vertical justification setting.
set vertical justification of text frame preferences of myTextFrame to myVerticalJustification
--Apply the paragraph alignment ("justification").
--"text 1 of myTextFrame" is all of the text in the text frame.
set justification of text 1 of myTextFrame to myParagraphAlignment
--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 end myMakeDocument
Working with ScriptUI
JavaScripts can make create and define user-interface elements using an Adobe scripting component named ScriptUI. ScriptUI gives scripters a way to create floating palettes, progress bars, and interactive dialog boxes that are far more complex than InDesign’s built-in dialog
object.
This does not mean, however, that user-interface elements written using Script UI are not accessible to
AppleScript users. InDesign scripts can execute scripts written in other scripting languages using the do script method.
Creating a progress bar with ScriptUI
The following sample script shows how to create a progress bar using JavaScript and ScriptUI, then use the progress bar from an AppleScript (for the complete script, see ProgressBar):
C HAPTER 7: User Interfaces Working with ScriptUI 137
#targetengine "session"
//Because these terms are defined in the "session" engine,
//they will be available to any other JavaScript running
//in that instance of the engine.
var myMaximumValue = 300; var myProgressBarWidth = 300; var myIncrement = myMaximumValue/myProgressBarWidth; myCreateProgressPanel(myMaximumValue, myProgressBarWidth); function myCreateProgressPanel(myMaximumValue, myProgressBarWidth){ myProgressPanel = new Window('window', 'Progress'); with(myProgressPanel){ myProgressPanel.myProgressBar = add('progressbar', [12, 12, myProgressBarWidth, 24], 0, myMaximumValue);
}
}
The following script fragment shows how to call the progress bar created in the above script using an
AppleScript (for the complete script, see CallProgressBar): set myDocument to make document
--Add pages to the active document.
--If you don't do this, the progress bar will
--go by too quickly.
--Note that the JavaScripts must use the "session"
--engine for this to work.
set myJavaScript to "#targetengine \"session\"" & return set myJavaScript to myJavaScript & "myCreateProgressPanel(100, 400);" & return set myJavaScript to myJavaScript & "myProgressPanel.show();" & return do script myJavaScript language javascript repeat with myCounter from 1 to 40 set myJavaScript to "#targetengine \"session\"" & return set myJavaScript to myJavaScript & "myProgressPanel.myProgressBar.value = " set myJavaScript to myJavaScript & myCounter & "/myIncrement;" & return do script myJavaScript language javascript tell myDocument to make page if myCounter = 100 then set myJavaScript to "#targetengine \"session\"" & return set myJavaScript to myJavaScript &
"myProgressPanel.myProgressBar.value = 0;" & return set myJavaScript to myJavaScript & "myProgressPanel.hide();" & return do script myJavaScript language javascript close myDocument saving no end if end repeat
பதிவிறக்கு
விளம்பரம்