Page 2
Adobe Systems Incorporated. Please note that the content in this guide is protected under copyright law even if it is not distributed with software that includes an end user license agreement.
We discuss the software you need to start writing your own scripts. After you learn the basics of InDesign scripting in this tutorial, you can move on to Adobe InDesign CS4 Scripting Guide, which explores scripting in more depth. Adobe InDesign CS4 Scripting Guide contains hundreds of tutorial scripts covering topics like text formatting, finding and changing text, associating scripts with menu items, drawing objects on a page, and exporting documents.
Adobe InDesign CS4 Scripting Tutorial Getting started 6 Installing scripts Installing an InDesign script is easy: put the script file in the Scripts Panel folder inside the Scripts folder in your InDesign application folder. (Create the Scripts folder if it does not already exist.) Alternately, put the script inside the Scripts Panel folder in your preferences folder.
ExtendScript. ExtendScript examples do not work in other JavaScript versions. : Because ExtendScript tools and features are used in several Adobe products, we consolidated all ExtendScript documentation. To learn more about JavaScript utilities like the ScriptUI user-interface module and the ExtendScript Toolkit (a JavaScript development environment and object-model inspector), see Creative Suite 4 JavaScript Tools Guide.
Mac OS and Windows versions of InDesign, use JavaScript. If you need to communicate with other, non-Adobe applications on your system, use the appropriate, platform standard language (AppleScript on Mac OS or VBScript in Windows).
Adobe InDesign CS4 Scripting Tutorial Getting started 9 Your first InDesign script Next, we will create an InDesign script that creates a new document, adds a text frame, and enters text in the text frame. This demonstrates how to do the following: ➤...
Adobe InDesign CS4 Scripting Tutorial Getting started 10 Save the script as a text file with the file extension to the Scripts Panel folder (see “Installing scripts” .vbs on page 6). To run the script, double-click the script name in the Scripts panel.
Adobe InDesign CS4 Scripting Tutorial Scripting and the InDesign object model 11 Scripting and the InDesign object model This section discusses the terminology of scripting languages in general and InDesign scripting in particular. Scripting terminology This section discusses common scripting terms and concepts.
Page 12
Adobe InDesign CS4 Scripting Tutorial Scripting and the InDesign object model 12 Value type What it is Example Boolean Logical True or False. True Integer Whole numbers (no decimal points). Integers can be positive or negative. In VBScript, you can use the long data type for integers.
Adobe InDesign CS4 Scripting Tutorial Scripting and the InDesign object model 13 VBScript Rem To convert from a number to a string: myNumber = 2 myString = cstr(myNumber) Rem To convert from a string to an integer: myString = "2"...
Page 14
Adobe InDesign CS4 Scripting Tutorial Scripting and the InDesign object model 14 Array variables AppleScript, JavaScript, and VBScript support arrays, which is a variable type that is a list of values. In AppleScript, an array is called a list. Examples of defining arrays are shown below:...
Adobe InDesign CS4 Scripting Tutorial Scripting and the InDesign object model 15 JavaScript //Given a variable of unknown type, "myMysteryVariable"... myType = myMysteryVariable.constructor.name; //myType will be a string corresponding to the JavaScript type (e.g., "Rectangle") VBScript Rem Given a variable of unknown type, "myMysteryVariable"...
Adobe InDesign CS4 Scripting Tutorial Scripting and the InDesign object model 16 Functions and handlers Functions (in VBScript or JavaScript) or handlers (in AppleScript) are scripting modules you can refer to within your script. Typically, you send a value or series of values to a function (or handler) and get back some other value or values.
Page 17
Adobe InDesign CS4 Scripting Tutorial Scripting and the InDesign object model 17 application documents a document libraries document preferences books document defaults application preferences document events application defaults document properties application events document methods application menus document elements application properties...
Adobe InDesign CS4 Scripting Tutorial Scripting and the InDesign object model 18 Term What it represents Document Document default settings, such as colors, paragraph styles, and text formatting defaults defaults. Document For example, the stories, imported graphics, and pages of a document. The figure...
Page 19
Adobe InDesign CS4 Scripting Tutorial Scripting and the InDesign object model 19 AppleScript To view the InDesign AppleScript dictionary, follow these steps: 1. Start InDesign. 2. Start the Apple Script Editor. 3. In the Script Editor, choose File > Open Dictionary. The Script Editor displays a list of scriptable applica- tions: 4.
Page 20
1. Start the ExtendScript Toolkit. 2. Choose Help > Object Model Viewer. 3. Select Adobe InDesign CS4 Object Model in the Browser pane. The ExtendScript Toolkit loads object model help file and displays a list of InDesign scripting objects in the Classes pane.
Page 21
2. From the list of available references, select Adobe InDesign CS4 Type Library, and click OK. If the library does not appear in the list of available references, click Browse and locate and select the file Resources for Visual Basic.tlb, which is usually inside...
Page 22
2. Select the COM tab. 3. From the list of available references, select Adobe InDesign CS4 Type Library, and click Select. Visual Basic.NET adds the reference to the Selected Components list. If the library does not appear in the list...
Page 23
3. Choose Tools > References. The Visual Basic Editor displays the Add References dialog box: 4. From the list of available references, select Adobe InDesign CS4 Type Library option, and click Select. Visual Basic adds the reference to the Selected Components list. If the library does not appear in the list of available references, click Browse and locate and select the Resources for Visual Basic.tlb...
Adobe InDesign CS4 Scripting Tutorial Scripting and the InDesign object model 24 Measurements and positioning All items and objects in InDesign are positioned on the page according to measurements you choose. It is useful to know how the InDesign coordinate system works and what measurement units it uses.
Adobe InDesign CS4 Scripting Tutorial Adding features to “Hello World” 25 Override Meaning Example Picas (add points after the p, if necessary) Points 18pt Adding features to “Hello World” Next, we will create a new script that makes changes to the “Hello World” publication that we created with our first script.
Adobe InDesign CS4 Scripting Tutorial Adding features to “Hello World” 26 tell text frame 1 of page 1 --Resize the text frame to match the page margins. set geometric bounds to myBounds tell paragraph 1 --Change the font, size, and paragraph alignment.
Adobe InDesign CS4 Scripting Tutorial Adding features to “Hello World” 27 1. Enter the following JavaScript in a new text file: //Improved Hello World! //Enter the name of a font on your system, if necessary. try{ myFont = app.fonts.item("Arial"); catch (myError){};...
Page 28
Adobe InDesign CS4 Scripting Tutorial Adding features to “Hello World” 28 Either open the tutorial script, or perform the following steps to create the ImprovedHelloWorld.vbs script: 1. Start any text editor (for example, Notepad). 2. Enter the following code: Set myInDesign = CreateObject("InDesign.Application.CS4") Rem Enter the name of a font on your system, if necessary.
Adobe InDesign CS4 Scripting Tutorial Constructing a document 29 Constructing a document Obviously, our “Hello World!” script would not be very useful in your daily work, but it’s shown you the basics of InDesign scripting. In the following section, we’ll show a script that does a bit more, and demonstrates scripting techniques you’re likely to use in your own scripts.
Page 30
Adobe InDesign CS4 Scripting Tutorial Constructing a document 30 app.gridPreferences document.gridPreferences baselineColor baselineStart baselineGridRelativeOption baselineDivision baselineViewThreshold gridColor verticalGridlineDivision verticalGridSubdivision horizontalGridlineDivision horizontalGridSubdivision gridsInBack baselineGridShown documentGridShown documentGridSnapTo In the following sections, we’ll discuss each functional area in the script. Open DocumentConstruction this script in the script editor for the language of your choice if you’d like to follow along.
Adobe InDesign CS4 Scripting Tutorial Constructing a document 31 Setting up measurement units and master spread margins The following script fragment shows how to create a new document and set the margins of the first master spread. AppleScript tell application "Adobe InDesign CS4"...
Adobe InDesign CS4 Scripting Tutorial Constructing a document 32 //Page margins and columns for the right-hand page. var myMarginPreferences = myMasterSpread.pages.item(1).marginPreferences; myMarginPreferences.left = 84; myMarginPreferences.top = 70; myMarginPreferences.right = 70; myMarginPreferences.bottom = 78; myMarginPreferences.columnCount = 3; myMarginPreferences.columnGutter = 14; VBScript Either enter the following code in your script or text editor, or open the DocumentConstruction.vbs...
Adobe InDesign CS4 Scripting Tutorial Constructing a document 33 AppleScript set myGridPreferences to grid preferences set baseline division of myGridPreferences to 14 set baseline start of myGridPreferences to 70 set baseline grid shown of myGridPreferences to true JavaScript var myGridPreferences = myDocument.gridPreferences;...
Adobe InDesign CS4 Scripting Tutorial Constructing a document 34 AppleScript set myLeftPage to page 1 of myMasterSpread set myRightPage to page 2 of myMasterSpread tell myLeftPage set myLeftFooter to make text frame set geometric bounds of myLeftFooter to {728, 70, 742, 528}...
Adobe InDesign CS4 Scripting Tutorial Constructing a document 36 AppleScript tell myLeftPage set myLeftTextFrame to make text frame set geometric bounds of myLeftTextFrame to {70, 70, 714, 528} set first baseline offset of text frame preferences of myLeftTextFrame to leading...
Adobe InDesign CS4 Scripting Tutorial Constructing a document 37 Rem Add a label to make the frame easier to find later on. myLeftTextFrame.Label = "BodyTextFrame" Set myRightTextFrame = myRightPage.TextFrames.Add myRightTextFrame.GeometricBounds = Array(70, 84, 714, 542) myRightTextFrame.TextFramePreferences.FirstBaselineOffset = idFirstBaseline.idLeadingOffset myRightTextFrame.TextFramePreferences.TextColumnCount = 3 myRightTextFrame.TextFramePreferences.TextColumnGutter = 14...
Adobe InDesign CS4 Scripting Tutorial Constructing a document 38 Adding and applying a paragraph style Our headline looks plain, so we will format it using a paragraph style. To do that, we must create the paragraph style. The following diagram shows the objects and properties we will work with (again, the text...
Adobe InDesign CS4 Scripting Tutorial Constructing a document 39 set fill color of myParagraphStyle to color "Red" of myDocument --Apply the style to the paragraph. tell paragraph 1 of myTextFrame to apply paragraph style using myParagraphStyle with clearing overrides --You could also use:...
Adobe InDesign CS4 Scripting Tutorial Constructing a document 40 If Error.Number <> 0 Then Set myColor = myDocument.Colors.Add myColor.Name = "Red" myColor.Model = idColorModel.idProcess myColor.colorValue = Array(0, 100, 100, 0) Error.Clear End If Rem Resume normal error handling. On Error GoTo 0 Rem Now set the formatting of the paragraph style.
Adobe InDesign CS4 Scripting Tutorial Constructing a document 41 VBScript Rem Display a standard open file dialog box to select a text file. Rem VBScript does not have the ability to do this, so we'll use Rem a JavaScript to get a file name. We'll run the JavaScript using Rem InDesign's DoScript feature.
Adobe InDesign CS4 Scripting Tutorial Constructing a document 42 --Resize the frame to a specific size. set geometric bounds of myFrame to {0, 0, 144, 144} --Fit the graphic to the frame proportionally. fit myFrame given proportionally --Next, fit frame to the resized graphic.
Adobe InDesign CS4 Scripting Tutorial Constructing a document 43 //Move the graphic frame. var myPageWidth = myDocument.documentPreferences.pageWidth; var myTopMargin = myDocument.pages.item(0).marginPreferences.top; myFrame.move([myPageWidth-myGraphicWidth, myTopMargin]); //Apply a text wrap to the graphic frame. myFrame.textWrapPreferences.textWrapType = TextWrapTypes.boundingBoxTextWrap; myFrame.textWrapPreferences.textWrapOffset = [24, 12, 24, 12];...
InDesign scripting. In each example, we created objects, set object properties, and used object methods. For your next step in learning about InDesign scripting, see the Adobe InDesign CS4 Scripting Guide. It offers more advanced tutorials on constructing documents, formatting text, finding and changing text, building user interfaces, adding menu items, and working with XML and XML rules.
Need help?
Do you have a question about the 65024872 - InDesign CS4 - Mac and is the answer not in the manual?
Questions and answers