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.
Adobe InDesign CS2 Scripting Guide Contents Contents Introduction ..............1 What is in this book ...................... 1 Who should read this book ..................1 What you need to use scripting ................1 JavaScript ..Macintosh ..Windows ..How to use the scripts in this document .............. 2 Copying examples with long lines ..................
Page 4
Contents Adobe InDesign CS2 Scripting Guide Control structures ....................... 15 Conditional statements ......................15 Loops ... Subroutines and handlers ..................17 Getting Started with InDesign Scripting ....19 Measurements and positioning ................19 Coordinates ..........................19 Measurement units ........................20 The InDesign document object model ............... 21 Looking at the InDesign object model ................21...
Page 5
Adobe InDesign CS2 Scripting Guide Contents User notification helper functions ................. 63 Global alert function ......................64 Global confirm function .......................64 Global prompt function .......................65 Specifying measurement values ................66 UnitValue object ........................66 Converting pixel and percentage values ...............67 Computing with unit values ....................68 Modular programming support ................
Page 6
Contents Adobe InDesign CS2 Scripting Guide Exporting a document as PDF ................104 Using current PDF export options ................. 104 Setting PDF export options ..................... 104 Exporting a range of pages ..................... 106 Exporting pages separately ..................... 106 Exporting pages as EPS ...................107 Exporting all pages ......................
Page 7
Adobe InDesign CS2 Scripting Guide Contents Working with Documents in VBScript ....143 Basic document management ................144 Creating a new document ....................144 Opening a document ......................144 Closing a document ......................145 Saving a document ......................145 Basic page layout ......................146 Defining page size and document length ..............146 Defining bleed and slug areas ..................
Introduction Introduction If you’re reading this, you’ve discovered the most powerful feature in Adobe® InDesign® CS2. No other feature—no tool, palette, or dialog box that you see in the program’s user interface—can save you as much time, trouble, and money as scripting.
How to use the scripts in this document To use any script from this document: 1. Copy the script from this Adobe® PDF® document and paste it into your script editor, such as Notepad in Windows or TextEdit in Mac OS.
ExtendScript Toolkit and run the script. Where to find more information The Adobe InDesign CS2 Scripting Reference provides details about the objects, properties, and methods available for scripting in InDesign.
Introduction Adobe InDesign CS2 Scripting Guide InDesign online scripting resources For more information on InDesign scripting, visit: http://partners.adobe.com/public/developer/scripting/index.html http://www.adobeforums.com, the InDesign Scripting User-to-User forum. In the forum, scripters can ask questions, post answers, and share their newest scripts. The forum contains hundreds of example scripts.
Adobe InDesign CS2 Scripting Guide Scripting Basics Scripting Basics If you’ve used InDesign, you’ve worked with frames and their contents, and you’ve learned to apply colors, formatting, and styles. You’ve set up publications, spreads, pages, and the design elements on those pages. If you’ve done all of this, you’ve gotten used to thinking of an InDesign publication as a collection of objects.
Scripting Basics Adobe InDesign CS2 Scripting Guide On the Macintosh, scripting is often accomplished using AppleScript, a scripting system that sends messages to applications or to the operating system using AppleEvents. In Windows, VBScript programs use a similar system for interapplication communication, usually referred to as Windows Automation. JavaScripts, by contrast, run on either platform.
Adobe InDesign CS2 Scripting Guide Scripting Basics Making script files readable Comments within scripts and formatting of scripts make them easier to understand and to maintain. Commenting the script Comments let you add descriptive text to a script. The scripting system ignores comments as the script executes;...
Scripting Basics Adobe InDesign CS2 Scripting Guide Objects and classes The terminology of object-oriented programming can be hard to understand, at first. This section defines commonly used terms and provides examples. Objects Objects belong to classes, and have properties that you manipulate using methods (Windows) or commands (Macintosh).
Adobe InDesign CS2 Scripting Guide Scripting Basics AppleScript first text frame of the first spread of the first document Note: When your AppleScript refers to a text object, InDesign returns the text contained in the object—not a reference to the object itself. To get a reference to the text object, use the object reference property, as shown in this example: tell application "Adobe InDesign CS2"...
Scripting Basics Adobe InDesign CS2 Scripting Guide Value type What it is Example 13.9972 Double (VBScript), A high-precision number that can con- fixed or real (Apple- tain a decimal point. Script), floating point (JavaScript) "I am a string" String A series of text characters. Strings ap- pear inside (straight) quotation marks.
Adobe InDesign CS2 Scripting Guide Scripting Basics The same operation in JavaScript is more similar to VBScript than it is to AppleScript (in InDesign JavaScript, is a reference to the InDesign application). To refer to an existing frame: var myTextFrame = app.documents[0].spreads[0].textFrames[0];...
Scripting Basics Adobe InDesign CS2 Scripting Guide Like VB.NET, JavaScript does not require Set when you assign values to variables, regardless of the type of the variable: var myDocument = app.documents.add(); var myString = "X"; Array variables AppleScript, VBScript, and JavaScript all support arrays, which is a variable type that is a list of values. In AppleScript, an array is called a list.
Adobe InDesign CS2 Scripting Guide Scripting Basics 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" myNumber = cInt(myString) Rem If your string contains a decimal value, use "cDbl" rather than "cInt":...
Scripting Basics Adobe InDesign CS2 Scripting Guide for(myCounter = 0; myCounter < app.activeDocument.pages.item(0).pageItems.length; myCounter ++){ var myPageItem = app.activeDocument.pages.item(0).pageItems.item(myCounter); var myPageItemType = myPageItem.getElements()[0].constructor.name; alert(myPageItemType); Operators Operators use variables or values to perform calculations (addition, subtraction, multiplication, and division) and return a value. For example: MyWidth/2 returns a value equal to half of the content of the variable myWidth .
Adobe InDesign CS2 Scripting Guide Scripting Basics AppleScript In AppleScript, you can also use the “with properties” to specify object properties as the object is created. tell application "Adobe InDesign CS2" --Example of an optional parameter (requires that you have a document preset --named "7x9_book_cover").
Scripting Basics Adobe InDesign CS2 Scripting Guide AppleScript tell application "Adobe InDesign CS2" if (count documents) = 0 then display dialog "No InDesign documents are open!" end if end tell VBScript Set myInDesign = CreateObject ("InDesign.Application.CS2") If myInDesign.Documents.Count = 0 MsgBox "No InDesign documents are open!"...
Adobe InDesign CS2 Scripting Guide Scripting Basics VBScript Here is a simple loop: For counter = 1 to 20 Rem do something Next Here is a conditional loop: Do While myStop = false Rem do something, at some point setting myStop to true to leave the loop.
Page 26
Scripting Basics Adobe InDesign CS2 Scripting Guide VBScript Rem Calculate the geometric center of a selected page item Rem Assumes you have a single page item selected. Set myInDesign = CreateObject("InDesign.Application.CS2") Set mySelection = myInDesign.Selection.Item(1) myCenterPoint = myCalculateCenterPoint(mySelection) MsgBox "x center: " & myCenterPoint(0) & vbCr & "y center: " & myCenterPoint(1) Function myCalculateCenterPoint(myObject) myBounds = myObject.GeometricBounds...
Adobe InDesign CS2 Scripting Guide Getting Started with InDesign Scripting Getting Started with InDesign Scripting This chapter gives background information that is important for you to know when creating scripts for InDesign. It also provides simple examples of common InDesign scripting operations. Even if you’re experienced with AppleScript, VBScript, or JavaScript, you should read this chapter, as it covers a number of InDesign-specific matters.
JavaScript and VBScript If you’re using JavaScript or VBScript to write your InDesign scripts, you can't view the InDesign object model as you can in AppleScript or VBScript. Instead, refer to the corresponding chapter of the Adobe InDesign Scripting Reference.
1. In any Visual Basic project, choose Project > References. Visual Basic displays the References dialog box. 2. Select the Adobe InDesign CS2 Type Library option from the list of available references 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 ~:\Documents and Settings\user_name\Application...
Adobe InDesign CS2 Scripting Guide Getting Started with InDesign Scripting --Hello World tell application "Adobe InDesign CS2" --Create a new document and assign its --identity to the variable "myDocument" set myDocument to make document tell myDocument --Create a new text frame on the first page.
Page 32
Getting Started with InDesign Scripting Adobe InDesign CS2 Scripting Guide 2. Use the CommandButton tool to create a new button on the default form. Double-click the button to open the Code window. 3. Enter the following code (between the Private Sub and End Sub lines defining the code under the button).
Adobe InDesign CS2 Scripting Guide Getting Started with InDesign Scripting Adding features to “Hello World” Next, let’s create a new script that makes changes to the “Hello World” publication that we created with our first script. Our second script demonstrates how to: Get the active document.
Page 34
Getting Started with InDesign Scripting Adobe InDesign CS2 Scripting Guide set justification to center align end tell end tell end tell end tell --myGetBounds is a handler that returns the bounds of the "live area" of a page. on myGetBounds(myDocument, myPage) tell application "Adobe InDesign CS2"...
Page 35
Adobe InDesign CS2 Scripting Guide Getting Started with InDesign Scripting 4. Save the text as a plain text file with the file extension .vbs in the Scripts folder inside the Presets folder in your InDesign folder. 5. Run the new script by double-clicking the script name in the InDesign Scripts palette.
Page 36
Getting Started with InDesign Scripting Adobe InDesign CS2 Scripting Guide 6. Save the form. 7. Click the button you created in Step 3 to run the new script. JavaScript To create the script: 1. Make sure that you have the Hello World document open; if you’ve closed the document without saving it, simply run the previous script again to make a new Hello World document.
Adobe InDesign CS2 Scripting Guide Getting Started with InDesign Scripting Adding a user interface to "Hello World" If you want your script to collect and act on information entered by you or by any other user of your script, you can add a user interface to the script. AppleScript, VBScript, and JavaScript can create dialog boxes for simple yes/no questions and text entry, but you might want to create more complex dialog boxes.
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...
Page 39
Adobe InDesign CS2 Scripting Guide Getting Started with InDesign Scripting set myPageWidth to page width of document preferences of myDocument set myLeft to left of margin preferences of myPage set myTop to top of margin preferences of myPage set myRight to right of margin preferences of myPage...
Page 40
Getting Started with InDesign Scripting Adobe InDesign CS2 Scripting Guide JavaScript 1. Enter the following JavaScript using any text editor or the ExtendScript Toolkit. //Simple User Interface Example var myDialog = app.dialogs.add({name:"Simple User Interface Example Script",canCancel:true}); with(myDialog){ //Add a dialog column.
Adobe InDesign CS2 Scripting Guide Getting Started with InDesign Scripting Creating a more complex user interface In the next example, we’ll add more controls and different types of controls to the example dialog box. The example creates a dialog box that resembles the following: AppleScript 1.
Page 42
Getting Started with InDesign Scripting Adobe InDesign CS2 Scripting Guide tell myDialogColumn make static text with properties {static label:"Vertical Justification:"} end tell set myDialogColumn to make dialog column tell myDialogColumn set myVerticalJustificationMenu to make dropdown with properties ¬ {string list:{"Top", "Center", "Bottom"}, selected index:0}...
Page 43
Adobe InDesign CS2 Scripting Guide Getting Started with InDesign Scripting set myLeft to left of margin preferences of myPage set myTop to top of margin preferences of myPage set myRight to right of margin preferences of myPage set myBottom to bottom of margin preferences of myPage...
Page 44
Getting Started with InDesign Scripting Adobe InDesign CS2 Scripting Guide Set myTempDialogColumn = myBorderPanel.DialogColumns.Add Set myRadioButtonGroup = myTempDialogColumn.RadiobuttonGroups.Add Set myLeftRadioButton = myRadioButtonGroup.RadiobuttonControls.Add myLeftRadioButton.StaticLabel = "Left" myLeftRadioButton.CheckedState = True Set myCenterRadioButton = myRadioButtonGroup.RadiobuttonControls.Add myCenterRadioButton.StaticLabel = "Center" Set myRightRadioButton = myRadioButtonGroup.RadiobuttonControls.Add myRightRadioButton.StaticLabel = "Right"...
Page 45
Adobe InDesign CS2 Scripting Guide Getting Started with InDesign Scripting JavaScript 1. Enter the following JavaScript using any text editor. //Complex User Interface Example //Create a dialog. var myDialog = app.dialogs.add({name:"User Interface Example Script", canCancel:true}); with(myDialog){ //Add a dialog column.
Page 46
Getting Started with InDesign Scripting Adobe InDesign CS2 Scripting Guide if(myVerticalJustificationMenu.selectedIndex == 0){ myVerticalJustification = VerticalJustification.topAlign; else if(myVerticalJustificationMenu.selectedIndex == 1){ myVerticalJustification = VerticalJustification.centerAlign; else{ myVerticalJustification = VerticalJustification.bottomAlign; //Get the paragraph alignment setting from the radiobutton group. if(myRadioButtonGroup.selectedButton == 0){ myParagraphAlignment = Justification.leftAlign;...
Adobe InDesign CS2 Scripting Guide Getting Started with InDesign Scripting Handling errors Imagine that you’ve written a script that formats the current text selection. What should the script do if the current selection turns out not to be text at all, but a rectangle, oval, or polygon? Error handling is code that you add to your script to respond to conditions other than those that you expect it to encounter.
Getting Started with InDesign Scripting Adobe InDesign CS2 Scripting Guide else { //No documents are open, so display an error message. alert("No InDesign documents are open. Please open a document and try again.") You can also use JavaScript’s “try…catch” statement for error handling, as shown in the example below: //Display the type of the first item in the selection.
Adobe InDesign CS2 Scripting Guide Getting Started with InDesign Scripting run a script using the Scripts palette, InDesign suppresses screen drawing until the script has finished. To view the script actions as they execute, choose Enable Redraw from the Scripts palette menu.
Getting Started with InDesign Scripting Adobe InDesign CS2 Scripting Guide Testing and troubleshooting Scripting environments provide tools for monitoring the progress of your script as it runs. This makes it easier to find problems that your script might encounter or cause.
Using ExtendScript Tools and Features Using ExtendScript Tools and Features ExtendScript is Adobe’s extended implementation of JavaScript, and is used by all Adobe Creative Suite 2 applications that provide a scripting interface. In addition to implementing the JavaScript language according to the W3C specification, ExtendScript provides certain additional features and utilities.
The ExtendScript Toolkit The ExtendScript Toolkit provides an interactive development and testing environment for ExtendScript in all Adobe Creative Suite 2 applications. It includes a full-featured, syntax-highlighting editor with Unicode capabilities and multiple undo/redo support. The Toolkit allows you to: Single-step through JavaScripts inside a CS2 application.
Selecting a debugging target The Toolkit can debug multiple applications at one time. If you have more than one Adobe Creative Suite 2 application installed, use the drop-down list at the upper left under the menu bar to select the target application.
Toolkit prompts you to switch to it. If you select an application that cannot be debugged in the Toolkit (such as Adobe Help), an error dialog reports that the Toolkit cannot connect to the selected application.
Adobe InDesign CS2 Scripting Guide Using ExtendScript Tools and Features Tracking data The Data Browser tab is your window into the JavaScript engine. It displays all live data defined in the current context, as a list of variables with their current values. If execution has stopped at a breakpoint, it shows variables that have been defined using var in the current function, and the function arguments.
Using ExtendScript Tools and Features Adobe InDesign CS2 Scripting Guide The JavaScript console The JavaScript console is a command shell and output window for the currently selected JavaScript engine. It connects you to the global namespace of that engine. JavaScript command line JavaScript output The command line entry field accepts any JavaScript code, and you can use it to evaluate expressions or...
Adobe InDesign CS2 Scripting Guide Using ExtendScript Tools and Features Switching between the functions in the call hierarchy allows you to trace how the current function was called. The Console and Data Browser tabs coordinate with the Call Stack pane. When you select a function in the Call...
Using ExtendScript Tools and Features Adobe InDesign CS2 Scripting Guide Right arrow Move insertion point right one character Up arrow Move insertion point up one line; stay in column if possible Down arrow Move insertion point down one line; stay in column if possible...
Page 59
Adobe InDesign CS2 Scripting Guide Using ExtendScript Tools and Features the variables and functions are already known to the JavaScript engine. During debugging, however, this is an extremely useful way to display the current value of a variable, along with its current data type.
Page 60
Using ExtendScript Tools and Features Adobe InDesign CS2 Scripting Guide If the script encounters a runtime error, the Toolkit halts the execution of the script, displays the current script with the current line highlighted in red, displays the error message in the status line, and plays a sound.
Page 61
Adobe InDesign CS2 Scripting Guide Using ExtendScript Tools and Features You can set breakpoints on lines that do not contain any code, such as comment lines. When the Toolkit runs the program, it automatically moves such a breakpoint down to the next line that actually contains code.
Using ExtendScript Tools and Features Adobe InDesign CS2 Scripting Guide Profiling The Profiling tool helps you to optimize program execution. When you turn profiling on, the JavaScript engine collects information about a program while it is running. It counts how often the program executed a line or function, or how long it took to execute a line or function.
Adobe InDesign CS2 Scripting Guide Using ExtendScript Tools and Features Dollar ($) Object This global ExtendScript object provides a number of debugging facilities and informational methods. The properties of the $ object allow you to get global information such as the most recent run-time error, and set flags that control debugging and localization behavior.
Using ExtendScript Tools and Features Adobe InDesign CS2 Scripting Guide objects Number The total count of all JavaScript objects defined so far. Read only. String The current operating system version. Read only. screens Array An array of objects containing information about the display screens attached to your computer.
Page 65
Adobe InDesign CS2 Scripting Guide Using ExtendScript Tools and Features sleep Suspends the calling thread for the given number of milliseconds. milliseconds $.sleep ( Returns undefined . During a sleep period, checks at 100 millisecond intervals to see whether the sleep should be terminated. This can happen if there is a break request, or if the script timeout has expired.
Using ExtendScript Tools and Features Adobe InDesign CS2 Scripting Guide Prop A second reference count for the number of properties that reference the object. The garbage collector uses this count to break circular references. If the reference count is not equal to the number of JavaScript properties that reference it, the object is considered to be used elsewhere and is not garbage collected.
Adobe InDesign CS2 Scripting Guide Using ExtendScript Tools and Features Reflection object functions find Returns the ReflectionInfo object for the named property of the reflectionObj .find reflected object, or null if no such property exists. Use this method name to get information about dynamic properties that have not yet been accessed, but that are known to exist.
Using ExtendScript Tools and Features Adobe InDesign CS2 Scripting Guide dataType String The data type of the reflected element. One of: boolean number string : The class name of an object. Classname Note: Class names start with a capital letter. Thus, the value string stands for a JavaScript string, while String is a JavaScript wrapper object.
Adobe InDesign CS2 Scripting Guide Using ExtendScript Tools and Features For portions of your user interface that are displayed on the screen, you may want to localize the displayed text. You can localize any string explicitly using the Global localize function, which takes as its argument a localization object containing the localized versions of a string.
Using ExtendScript Tools and Features Adobe InDesign CS2 Scripting Guide Locale names A locale name is an identifier string in that contains an ISO 639 language specifier, and optionally an ISO 3166 region specifier, separated from the language specifier by an underscore.
Internal use only. A ZString is an internal Adobe format for localized strings, which you might see in Adobe scripts. It is a string that begins with $$$ and contains a path to the localized string in an installed ZString dictionary. For example: w = new Window ("dialog", localize ("$$$/UI/title1=Sample"));...
Using ExtendScript Tools and Features Adobe InDesign CS2 Scripting Guide These dialogs are customizable to a small degree. The appearance is platform specific. Global alert function alert Displays a platform-standard dialog containing a short alert (message[, title, errorIcon]); message and an OK button. Returns undefined .
Adobe InDesign CS2 Scripting Guide Using ExtendScript Tools and Features Examples ➤ This figure shows simple confirmation dialogs in Windows and Mac OS. This figure shows confirmation dialogs with No as the default button. Global prompt function prompt Displays a platform-standard dialog containing a short...
Using ExtendScript Tools and Features Adobe InDesign CS2 Scripting Guide This figure shows confirmation dialogs with a title value specified. Specifying measurement values ExtendScript provides the UnitValue object to represent measurement values. The properties and methods of the UnitValue object make it easy to change the value, the unit, or both, or to perform conversions from one unit to another.
Adobe InDesign CS2 Scripting Guide Using ExtendScript Tools and Features traditional pica traditional picas 12 tpt cicero ciceros 12.7872 pt pixel pixels baseless (see below) percent percent baseless (see below) If an unknown unit type is supplied, the type is set to “?” , and the UnitValue object prints as “UnitValue 0.00000”.
Using ExtendScript Tools and Features Adobe InDesign CS2 Scripting Guide To convert pixels into length units, you must know the size of a single pixel. The size of a pixel depends on the display resolution. A common resolution measurement is 72 dpi, which means that there are 72 pixels to the inch.
Adobe InDesign CS2 Scripting Guide Using ExtendScript Tools and Features If one operand is unitValue object and the other is a number, the operation is applied to the number and the numeric value of the object. The expression returns a new unitValue object with the result as its .
Page 78
Includes a JavaScript source file from another location. Inserts the contents of the named file into this file at the location of this statement. The file argument is an Adobe portable file specification. See the “Specifying Paths” section. As a convention, use the file extension . jsxinc for JavaScript include files. For example: #include "../include/lib.jsxinc"...
Adobe InDesign CS2 Scripting Guide Using ExtendScript Tools and Features #script name Names a script. Enclosing quotes are optional, but required for names that include spaces or special characters. For example: #script SetupPalette #script "Load image file" The name value is displayed in the Toolkit Editor tab. An unnamed script is assigned a unique name generated from a number.
Using ExtendScript Tools and Features Adobe InDesign CS2 Scripting Guide In calling the function, you deconstruct the object you want to pass into a serialized string: myFn (myObject.toSource()); // pass a serialized object Operator overloading ExtendScript allows you to extend or override the behavior of a math or a Boolean operator for a specific class by defining a method in that class with same name as the operator.
Bridge (which is integrated with all Adobe Creative Suite 2 (CS2) applications) uses an application speci- fier as the value of the document.owner property, to identify another CS2 application that created or opened a Bridge browser window.
For information about the cross-DOM and exported functions, see the Bridge JavaScript Reference, available with Adobe Creative Suite 2. Script locations and checking application installation On startup, all Adobe Creative Suite 2 applications execute all JSX files that they find in the user startup folder: In Windows, the startup folder is: %APPDATA%\Adobe\StartupScripts...
Adobe InDesign CS2 Scripting Guide Working with Documents in AppleScript Working with Documents in AppleScript Most of the work that you do in InDesign revolves around documents—creating them, saving them, and populating them with page items, colors, styles, and text. Documents are also important to InDesign scripting, and almost every document-related task can be automated using scripting.
Working with Documents in AppleScript Adobe InDesign CS2 Scripting Guide Basic document management In almost all situations, your script needs to either open or create a document, save it, and then close it. Creating a new document If a document does not already exist, you must create one. To create a document: --MakeDocument.as...
Adobe InDesign CS2 Scripting Guide Working with Documents in AppleScript --At this point, your script could change or get information --from the hidden document. tell myDocument to make window end tell Closing a document The close command closes a document: --CloseDocument.as...
Working with Documents in AppleScript Adobe InDesign CS2 Scripting Guide The save command has two optional parameters: The first ( to ) specifies the file to save to; the second ( stationery ) can be set to true to save the document as a template: --SaveDocumentAs.as...
Adobe InDesign CS2 Scripting Guide Working with Documents in AppleScript tell document preferences of myDocument set page height to "800pt" set page width to "600pt" set page orientation to landscape set pages per document to 16 end tell end tell Note: The application object also has a document preferences object.
Working with Documents in AppleScript Adobe InDesign CS2 Scripting Guide set myDocument to make document --The bleed properties belong to the document preferences object. tell document preferences of myDocument --Slug set document slug uniform size to true set slug top offset to "3p"...
Page 89
Adobe InDesign CS2 Scripting Guide Working with Documents in AppleScript set top to 36 set left to 36 set bottom to 48 set right to 36 end tell end tell InDesign does not allow you to create a page that is smaller than the sum of the relevant margins, that is, the width of the page must be greater than the sum of the current left and right page margins, and the height of the page must be greater than the sum of the top and bottom margins.
Working with Documents in AppleScript Adobe InDesign CS2 Scripting Guide set myX1 to left set myY2 to bottom set myX2 to right --Set the application default margin preferences. set top to 0 set left to 0 set bottom to 0...
Page 91
Adobe InDesign CS2 Scripting Guide Working with Documents in AppleScript tell application "Adobe InDesign CS2" set myDocument to make document set myPageWidth to page width of document preferences of myDocument set myPageHeight to page height of document preferences of myDocument...
Working with Documents in AppleScript Adobe InDesign CS2 Scripting Guide --Note that the createGuides method does not take an RGB array --for the guide color parameter. create guides number of rows 4 number of columns 4 row gutter "1p" ¬...
Adobe InDesign CS2 Scripting Guide Working with Documents in AppleScript Changing measurement units and ruler The example scripts so far used measurement strings (strings that force InDesign to use a specific measurement unit, “8.5i”, for example, for 8.5 inches). They do this because you might be using a different measurement system when you run the script.
Working with Documents in AppleScript Adobe InDesign CS2 Scripting Guide --DocumentPresetByExample.as --An InDesign CS2 AppleScript --Creates a new document preset based on the current document settings. tell application "Adobe InDesign CS2" if (count documents) > 0 then set myDocument to active document --If the document preset "myDocumentPreset"...
Adobe InDesign CS2 Scripting Guide Working with Documents in AppleScript with properties {name:"myDocumentPreset"} end try --Fill in the properties of the document preset. tell myDocumentPreset set page height to "9i" set page width to "7i" set left to "4p" set right to "6p"...
Page 96
Working with Documents in AppleScript Adobe InDesign CS2 Scripting Guide tell page 1 set myTextFrame to make text frame ¬ with properties {geometric bounds:{"61p", "4p", "62p", "45p"}} tell myTextFrame set contents of insertion point 1 to section marker set contents of insertion point 1 to Em space...
100 set balance ragged lines to false set baseline shift to 0 set capitalization to normal set composer to "Adobe Paragraph Composer" set desired glyph scaling to 100 set desired letter spacing to 0 set desired word spacing to 100...
Page 98
Working with Documents in AppleScript Adobe InDesign CS2 Scripting Guide set keep first lines to 2 set keep last lines to 2 set keep with next to 0 set kerning method to "Optical" set leading to 14 set left indent to 0...
"Olav Martin Kvern" set copyright info URL to "http://www.adobe.com" set copyright notice to "This document is copyrighted." set copyright status to yes set description to "Example of xmp metadata scripting in InDesign CS"...
Page 101
Adobe InDesign CS2 Scripting Guide Working with Documents in AppleScript --Slug set slug bottom offset to "18p" set slug top offset to "3p" set slug inside or left offset to "3p" set slug right or outside offset to "3p" end tell --Create a color.
Page 102
--Document XMP information. tell metadata preferences set author to "Olav Martin Kvern" set copyright info URL to "http:--www.adobe.com" set copyright notice to "This document is not copyrighted." set copyright status to no set description to "Example 7 x 9 book layout"...
Page 103
Adobe InDesign CS2 Scripting Guide Working with Documents in AppleScript set myDate to current date set myString to "Author:" & tab & author & tab & "Description:" ¬ & tab & description & return & "Creation Date:" & tab & myDate ¬...
Working with Documents in AppleScript Adobe InDesign CS2 Scripting Guide Printing a document The following script prints the active document using the current print preferences: --PrintDocument.as --An InDesign CS2 AppleScript --Prints the active document using the current print settings. tell application "Adobe InDesign CS2"...
Page 105
100 set scale mode to scale width height set scale proportional to true --If trapping is on (application built in or Adobe inRip), --attempting to set the following properties will produce an error. if trapping is off then...
Page 106
Working with Documents in AppleScript Adobe InDesign CS2 Scripting Guide set thumbnails to false --The following properties is not needed because thumbnails is set to false. --set thumbnails per page to 4 set tile to false --The following properties are not needed because tile is set to false.
Adobe InDesign CS2 Scripting Guide Working with Documents in AppleScript --set composite frequency to 175 --set simulate overprint to false -------------------------------------------------------------------------------- --Properties corresponding to the controls in the Graphics panel --of the Print dialog box. -------------------------------------------------------------------------------- set send image data to all image data...
Page 108
Working with Documents in AppleScript Adobe InDesign CS2 Scripting Guide --If the preset does not already exist, then create it of --print preferences of myDocument --otherwise, fill in the properties of the existing preset. tell application "Adobe InDesign CS2" set myPreset to printer preset "myPreset"...
Page 109
Adobe InDesign CS2 Scripting Guide Working with Documents in AppleScript print preferences of myDocument end try set paper gap of myPreset to paper gap of print preferences of myDocument end try set paper offset of myPreset to paper offset of ¬...
Page 110
Working with Documents in AppleScript Adobe InDesign CS2 Scripting Guide set bleed outside of myPreset to bleed outside of ¬ print preferences of myDocument end try set bleed marks of myPreset to bleed marks of print preferences of myDocument end try...
Page 111
Adobe InDesign CS2 Scripting Guide Working with Documents in AppleScript set black frequency of myPreset to black frequency of ¬ print preferences of myDocument end try set cyan angle of myPreset to cyan angle of print preferences of myDocument end try set cyan frequency of myPreset to cyan frequency of ¬...
--Assumes you have a document open --export command parameters are: --Format as (use either the pdf type enumeration or the string "Adobe PDF") --To as string (you’ll have to fill in a complete file path) --Showing options as boolean (setting this option to true displays...
Page 113
Adobe InDesign CS2 Scripting Guide Working with Documents in AppleScript set myX1Offset to document bleed inside or left offset set myY1Offset to document bleed top offset set myX2Offset to document bleed outside or right offset set myY2Offset to document bleed bottom offset...
--is PDF/X-1a or PDF/X-3 --set simulate overprint to false set use document bleed with PDF to true --Set viewPDF to true to open the PDF in Acrobat or Adobe Reader. set view PDF to false end tell --Now export the document.
Adobe InDesign CS2 Scripting Guide Working with Documents in AppleScript set myFolder to «class ktxt» of (myFolder as record) if myFolder is not equal to "" then my myExportPages(myFolder) end if end myChooseFolder on myExportPages(myFolder) tell application "Adobe InDesign CS2"...
Working with Documents in AppleScript Adobe InDesign CS2 Scripting Guide Exporting all pages The following script exports the pages of the active document to one or more EPS files: --ExportAsEPS.as --An InDesign CS2 AppleScript --Exports all of the pages in the active document to a series of EPS files --(an EPS, by definition, can contain only a single page).
Page 117
Adobe InDesign CS2 Scripting Guide Working with Documents in AppleScript end myChooseFolder on myExportPages(myFolder) tell application "Adobe InDesign CS2" set myDocument to active document set myDocumentName to name of myDocument set myDialog to make dialog with properties {name:"ExportPages"} tell myDialog...
Page 118
Working with Documents in AppleScript Adobe InDesign CS2 Scripting Guide...
Adobe InDesign CS2 Scripting Guide Working with Documents in JavaScript Working with Documents in JavaScript Most of the work that you do in InDesign revolves around documents—creating them, saving them, and populating them with page items, colors, styles, and text. Documents are also important to InDesign scripting, and almost every document-related task can be automated using scripting.
Working with Documents in JavaScript Adobe InDesign CS2 Scripting Guide Basic document management In almost all situations, your script needs to either open or create a document, save it, and then close it. Creating a new document If a document does not already exist, you must create one. To create a document: //MakeDocument.jsx...
Adobe InDesign CS2 Scripting Guide Working with Documents in JavaScript The close method can take up to two optional parameters: //CloseWithParameters.jsx //An InDesign CS2 JavaScript //Use SaveOptions.yes to save the document,SaveOptions.no to close the //document without saving, or SaveOptions.ask to display a prompt. If //you use SaveOptions.yes, you’ll need to provide a reference to a file...
Working with Documents in JavaScript Adobe InDesign CS2 Scripting Guide //If the file name contains the extension ".indd", change it to ".indt". if(myFileName.indexOf(".indd")!=-1){ var myRegularExpression = /.indd/gi myFileName = myFileName.replace(myRegularExpression, ".indt"); //If the document has not been saved, then give it a default file name/file path.
Adobe InDesign CS2 Scripting Guide Working with Documents in JavaScript //Slug slugBottomOffset = "18p"; slugTopOffset = "3p"; slugInsideOrLeftOffset = "3p"; slugRightOrOutsideOffset = "3p"; If all the bleed distances are equal, as in the preceding example, you can alternatively use the...
Page 124
Working with Documents in JavaScript Adobe InDesign CS2 Scripting Guide s.facingPages == true, //"left" means inside; "right" means outside. left = "6p" right = "4p" top = "4p" InDesign does not allow you to create a page that is smaller than the sum of the relevant margins, that is, the width of the page must be greater than the sum of the current left and right page margins, and the height of the page must be greater than the sum of the top and bottom margins.
Adobe InDesign CS2 Scripting Guide Working with Documents in JavaScript //Create a new example document to demonstrate the change. var myDocument = app.documents.add(); myDocument.documentPreferences.pageHeight = "1p"; myDocument.documentPreferences.pageWidth = "6p"; //Reset the application default margin preferences to their former state. with (app.marginPreferences){ top = myY1;...
Page 126
Working with Documents in JavaScript Adobe InDesign CS2 Scripting Guide guides.add(undefined, {orientation:HorizontalOrVertical.horizontal, location:(myPageHeight - marginPreferences.bottom)}); //Place a guide at the vertical center of the page. guides.add(undefined, {orientation:HorizontalOrVertical.vertical, location:(myPageWidth/2)}); //Place a guide at the horizontal center of the page. guides.add(undefined, {orientation:HorizontalOrVertical.horizontal, location:(myPageHeight/2)});...
Adobe InDesign CS2 Scripting Guide Working with Documents in JavaScript Setting grid preferences To control the properties of the document and baseline grid, you set the properties of the gridPreferences object, as shown in the following script: //DocumentAndBaselineGrids.jsx //An InDesign CS2 JavaScript //Creates a document, then sets preferences for the //document grid and baseline grid.
Adobe InDesign CS2 Scripting Guide Working with Documents in JavaScript try { var myPresetName = myDocumentPreset.name; catch (myError){ myDocumentPreset = app.documentPresets.add({name:"myDocumentPreset"}); //Set the application default measurement units to match the document //measurement units. app.viewPreferences.horizontalMeasurementUnits = myDocument.viewPreferences.horizontalMeasurement Units; app.viewPreferences.verticalMeasurementUnits = myDocument.viewPreferences.verticalMeasurementUnit //Fill in the properties of the document preset with the corresponding //properties of the active document.
Adobe InDesign CS2 Scripting Guide Working with Documents in JavaScript //Set up the right page (recto). with(pages.item(1)){ with(marginPreferences){ columnCount = 3; columnGutter = "1p"; bottom = "6p" //"left" means inside; "right" means outside. left = "6p" right = "4p" top = "4p"...
Adobe InDesign CS2 Scripting Guide Working with Documents in JavaScript Creating a document template This example creates a new document, defines slug and bleed areas, adds information to the document’s XMP metadata, sets up master pages, adds page footers, and adds job information to a table in the slug area: //DocumentTemplate.jsx...
Page 136
Working with Documents in JavaScript Adobe InDesign CS2 Scripting Guide //Create up a pair of paragraph styles for the page footer text. //These styles have only basic formatting. try{ myDocument.paragraphStyles.item("footer_left").name; catch (myError){ myDocument.paragraphStyles.add({name:"footer_left", pointSize:11, leading:14}); //Create up a pair of paragraph styles for the page footer text.
Page 137
Adobe InDesign CS2 Scripting Guide Working with Documents in JavaScript documentTitle = "Example"; jobName = "7 x 9 book layout template"; keywords = ["7 x 9", "book", "template"]; var myNewContainer = createContainerItem("http://ns.adobe.com/xap/1.0/", "email"); setProperty("http://ns.adobe.com/xap/1.0/", "email/*[1]", "okvern@adobe.com"); //Set up the master spread.
Working with Documents in JavaScript Adobe InDesign CS2 Scripting Guide myRightSlug.parentStory.tables.add(); //Body text master text frame. var myRightFrame = textFrames.add(myDocument.layers.item("BodyText"), undefined, undefined, {geometricBounds:[marginPreferences.top, marginPreferences.left, myBottomMargin, myRightMargin], previousTextFrame:myLeftFrame}); //Add section marker text--this text will appear in the footer. myDocument.sections.item(0).marker = "Section 1";...
Page 139
Adobe InDesign CS2 Scripting Guide Working with Documents in JavaScript reverseOrder = false; //pageRange can be either PageRange.allPages or a page range string. pageRange = PageRange.allPages; printSpreads = false; printMasterPages = false; //If the printer property is set to Printer.postScript file, then //the printFile property contains the file path to the output file.
Page 140
Working with Documents in JavaScript Adobe InDesign CS2 Scripting Guide textAsBlack = false; thumbnails = false; //The following properties is not needed because thumbnails is set to false. //thumbnailsPerPage = 4; tile = false; //The following properties are not needed because tile is set to false.
Adobe InDesign CS2 Scripting Guide Working with Documents in JavaScript profile = Profile.postscriptCMS; catch(e){} //-------------------------------------------------------------------------------- //Properties corresponding to the controls in the Advanced panel of the //Print dialog box. //-------------------------------------------------------------------------------- opiImageReplacement = false; omitBitmaps = false; omitEPS = false; omitPDF = false;...
Adobe InDesign CS2 Scripting Guide Working with Documents in JavaScript var myPDFExportPreset = app.pdfExportPresets.item("prepress"); app.activeDocument.exportFile(ExportFormat.pdfType, File("/c/myTestDocument.pdf"), false, myPDFExportPreset); Setting PDF export options and exporting pages separately The following example sets the PDF export options before exporting: //ExportEachPageAsPDF.jsx //An InDesign CS2 JavaScript //Exports each page of an InDesign CS document as a separate PDF to //a selected folder using the current PDF export settings.
= false; catch(e){} useDocumentBleedWithPDF = true; //Set viewPDF to true to open the PDF in Acrobat or Adobe Reader. viewPDF = false; //Now export the document. You’ll have to fill in your own file path. app.activeDocument.exportFile(ExportFormat.pdfType, File(“/c/myTestDocument.pdf”), false);...
Working with Documents in JavaScript Adobe InDesign CS2 Scripting Guide app.epsExportPreferences.pageRange = "1-3, 6, 9"; var myFile = new File("/c/myTestFile.eps"); app.activeDocument.exportFile(ExportFormat.epsType, myFile, false); Controlling export options In addition to the page range, you can control other EPS export options using scripting by setting the properties of the epsExportPreferences object.
Adobe InDesign CS2 Scripting Guide Working with Documents in VBScript Working with Documents in VBScript Most of the work that you do in InDesign revolves around documents—creating them, saving them, and populating them with page items, colors, styles, and text. Documents are also important to InDesign scripting, and almost every document-related task can be automated using scripting.
Working with Documents in VBScript Adobe InDesign CS2 Scripting Guide Basic document management In almost all situations, your script needs to either open or create a document, save it, and then close it. Creating a new document If a document does not already exist, you must create one. To create a document: Rem MakeDocument.vbs...
Adobe InDesign CS2 Scripting Guide Working with Documents in VBScript Closing a document The Close method closes a document: Rem CloseDocument.vbs Rem An InDesign CS2 VBScript Rem Closes the active document. Set myInDesign = CreateObject("InDesign.Application.CS2") myInDesign.ActiveDocument.Close Rem Note that you could also use: Rem myInDesign.Documents.Item(1).Close...
Working with Documents in VBScript Adobe InDesign CS2 Scripting Guide If myDocument.Saved = False Then Rem If you do not provide a file name, Rem InDesign displays the Save dialog box. myInDesign.ActiveDocument.Save "c:\myTestDocument.indd" End If The following example saves a document as a template: Rem SaveAsTemplate.vbs...
Page 155
Adobe InDesign CS2 Scripting Guide Working with Documents in VBScript you might want to omit slug information for the final printing of a document. The following script sets up the bleed and slug for a new document: Rem BleedAndSlug.vbs Rem An InDesign CS2 VBScript Rem Create a new document.
Working with Documents in VBScript Adobe InDesign CS2 Scripting Guide Setting page margins and columns Each page in a document can have its own margin and column settings. With InDesign scripting, these properties are part of the MarginPreferences object for each page. This example script creates a new document, then sets the margins and columns for all pages in the master spread: Rem MarginsAndColumns.vbs...
Adobe InDesign CS2 Scripting Guide Working with Documents in VBScript Rem The following assumes that your default master spread contains two pages. With myDocument.MasterSpreads.Item(1).Pages.Item(1).MarginPreferences .Top = 0 .Left = 0 .Bottom = 0 .Right = 0 .ColumnCount = 1 .ColumnGutter = 0 End With With myDocument.MasterSpreads.Item(1).Pages.Item(2).MarginPreferences...
Working with Documents in VBScript Adobe InDesign CS2 Scripting Guide Rem You can use either a number or a measurement string to set the space above/below. .MinimumSpaceAboveAndBelow = "12p" Rem You can set the preview background color (which you’ll only see Rem in Preview mode) to any of the predefined UIColor constants...
Page 159
Adobe InDesign CS2 Scripting Guide Working with Documents in VBScript Set myDocument = myInDesign.Documents.Add myDocument.DocumentPreferences.FacingPages = True myDocument.DocumentPreferences.PagesPerDocument = 3 With myDocument.Spreads.Item(2) Rem Note the difference between these two guides on pages 2 and 3. With .Guides.Add .Orientation = idHorizontalOrVertical.idHorizontal .Location = "6p"...
Working with Documents in VBScript Adobe InDesign CS2 Scripting Guide Rem Set the guide color of a guide using an RGB array. With .Guides.Add() .ItemLayer = myLayer .Orientation = idHorizontalOrVertical.idHorizontal .Location = "22p" .GuideColor = Array(192, 192, 192) End With End With You can also create guides using the CreateGuides method of spreads and master spreads.
Adobe InDesign CS2 Scripting Guide Working with Documents in VBScript With myDocument.GuidePreferences .GuidesInBack = True .GuidesLocked = False .GuidesShown = True .GuidesSnapto = True End With With myDocument.GridPreferences .DocumentGridShown = False .DocumentGridSnapto = True Rem Objects "snap" to the baseline grid when Rem GuidePreferences.GuideSnapTo is set to true.
Working with Documents in VBScript Adobe InDesign CS2 Scripting Guide Rem At this point, you can perform any series of script actions that Rem depend on the measurement units you’ve set. At the end of the Rem script, reset the units to their original state.
Adobe InDesign CS2 Scripting Guide Working with Documents in VBScript .PagesPerDocument = myDocument.DocumentPreferences.PagesPerDocument .SlugBottomOffset = myDocument.DocumentPreferences.SlugBottomOffset .SlugTopOffset = myDocument.DocumentPreferences.SlugTopOffset .SlugInsideOrLeftOffset = myDocument.DocumentPreferences.SlugInsideOrLeftOffset .SlugRightOrOutsideOffset = myDocument.DocumentPreferences.SlugRightOrOutsideOffset End With End If Creating a preset using new values To create a Document Preset using explicit values, run the following script: Rem DocumentPreset.vbs...
Page 164
Working with Documents in VBScript Adobe InDesign CS2 Scripting Guide Rem Set up the first master spread in a new document. Set myDocument = myInDesign.Documents.Add Rem Set up the document. With myDocument.DocumentPreferences .PageHeight = "11i" .PageWidth = "8.5i" .FacingPages = True .PageOrientation = idPageOrientation.idPortrait...
Adobe InDesign CS2 Scripting Guide Working with Documents in VBScript Use the same property to apply a master spread to a master spread page: Rem ApplyMasterToMaster.vbs Rem An InDesign CS2 VBScript Rem Applies a master page to a master page.
All this information is stored using XMP (Adobe Extensible Metadata Platform)—an open standard for embedding metadata in a document.
Page 169
Adobe InDesign CS2 Scripting Guide Working with Documents in VBScript Rem Creates a document template, including master pages, layers, Rem a color, paragraph and character styles, guides, and XMP information. Set myInDesign = CreateObject("InDesign.Application.CS2") Rem Set the application measurement unit defaults to points.
Page 170
Working with Documents in VBScript Adobe InDesign CS2 Scripting Guide Set myCharacterStyle = myDocument.CharacterStyles.Add myCharacterStyle.Name = "page_number" Err.Clear End If Rem restore normal error handling On Error GoTo 0 myDocument.CharacterStyles.Item("page_number").FillColor = myDocument.Colors.Item("PageNumberRed") Rem Create up a pair of paragraph styles for the page footer text.
Page 171
Adobe InDesign CS2 Scripting Guide Working with Documents in VBScript Rem restore normal error handling On Error GoTo 0 Rem Create a layer for the body text. Err.Clear On Error Resume Next Set myLayer = myDocument.Layers.Item("BodyText") If Err.Number <> 0 Then Set myLayer = myDocument.Layers.Add...
Page 172
Working with Documents in VBScript Adobe InDesign CS2 Scripting Guide .ItemLayer = myDocument.Layers.Item("GuideLayer") .Orientation = idHorizontalOrVertical.idHorizontal .Location = myBottomMargin .FitToPage = False End With With .Guides.Add .ItemLayer = myDocument.Layers.Item("GuideLayer") .Orientation = idHorizontalOrVertical.idHorizontal .Location = myBottomMargin + 14 .FitToPage = False End With With .Guides.Add...
Page 175
Adobe InDesign CS2 Scripting Guide Working with Documents in VBScript Rem -------------------------------------------------------------------------------- .PaperSize = idPaperSizes.idCustom Rem Page width and height are ignored if paperSize is not PaperSizes.custom. Rem .PaperHeight = 1200 Rem .PaperWidth = 1200 .PrintPageOrientation = idPrintPageOrientation.idPortrait .PagePosition = idPagePositions.idCentered .PaperGap = 0...
Page 176
Working with Documents in VBScript Adobe InDesign CS2 Scripting Guide Rem idTrapping.idAdobeInRIP. If .Trapping = idTrapping.idAdobeInRIP Then .PrintBlack = True .PrintCyan = True .PrintMagenta = True .PrintYellow = True End If Rem Only change the ink angle and frequency when you want to override the Rem screening set by the screening specified by the screening property.
Adobe InDesign CS2 Scripting Guide Working with Documents in VBScript Creating printer presets from printing preferences To create a printer preset from the print preferences of a document: Rem CreatePrinterPreset.vbs Rem An InDesign CS2 VBScript Rem Creates a new printer preset based on the print settings of the active document.
Rem Exports the active document as PDF. Set myInDesign = CreateObject("InDesign.Application.CS2") Rem Assumes you have a document open. Rem Document.Export parameters are: Rem Format: use either the idExportFormat.idPDFType constant or the string "Adobe PDF" Rem To: a file path as a string...
Adobe InDesign CS2 Scripting Guide Working with Documents in VBScript Rem ShowingOptions: boolean (setting this option to true displays the PDF Export dialog box) Rem Using: PDF export preset (or a string that is the name of a PDF export preset) Rem The default PDF export preset names are surrounded by squar breackets (e.g., "[Screen]").
.SimulateOverprint = False On Error GoTo 0 .UseDocumentBleedWithPDF = True Rem Set viewPDF to true to open the PDF in Acrobat or Adobe Reader. .ViewPDF = False End With Rem Now export the document. You’ll have to fill in your own file path.
Adobe InDesign CS2 Scripting Guide Working with Documents in VBScript End If Function myExportPages(myInDesign, myDocument, myFolderName) myDocumentName = myDocument.Name Set myDialog = myInDesign.Dialogs.Add With myDialog .Name = "ExportPages" With .DialogColumns.Add With .DialogRows.Add With .StaticTexts.Add .StaticLabel = "Base Name:" End With Set myBaseNameField = .TextEditboxes.Add...
Working with Documents in VBScript Adobe InDesign CS2 Scripting Guide Rem An InDesign CS2 VBScript. Rem Exports a range of pages as EPS files. Set myInDesign = CreateObject("InDesign.Application.CS2") Rem Enter the name of the page you want to export in the following line.
Page 183
Adobe InDesign CS2 Scripting Guide Working with Documents in VBScript Else myDialog.Destroy End If End Function...
Page 184
Working with Documents in VBScript Adobe InDesign CS2 Scripting Guide...
Need help?
Do you have a question about the 27510753 - InDesign CS2 - PC and is the answer not in the manual?
Questions and answers