Macromedia InDesign - CS6 User Guide

ADOBE® INDESIGN® CS6
ADOBE INDESIGN CS6
SCRIPTING GUIDE: APPLESCRIPT
2012 Adobe Systems Incorporated. All rights reserved.
Adobe® InDesign® CS6 Scripting Guide: AppleScript
Document Update Status
(for entire document; see each chapter for chapter-specific update status)
CS6 Updated Throughout document, changed CS5 to CS6 and version 7.0 to 8.0.
The content of this guide is furnished for informational use only, is subject to change without notice, and should not be construed as a commitment by Adobe Systems Incorporated. Adobe Systems Incorporated assumes no responsibility or liability for any errors or inaccuracies that may appear in the informational content contained in this guide.
Please remember that existing artwork or images that you may want to include in your project may be protected under copyright law. The unauthorized incorporation of such material into your new work could be a violation of the rights of the copyright owner. Please be sure to obtain any permission required from the copyright owner.
Any references to company names in sample templates are for demonstration purposes only and are not intended to refer to any actual organization.
Adobe, the Adobe logo, Creative Suite, and InDesign are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries. Microsoft and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Mac OS is a trademark of Apple Computer, Incorporated, registered in the United States and other countries. All other trademarks are the property of their respective owners.
Adobe Systems Incorporated, 345 Park Avenue, San Jose, California 95110, USA. Notice to U.S. Government End Users. The Software and Documentation are “Commercial Items,” as that term is defined at 48 C.F.R. §2.101, consisting of “Commercial Computer Software” and “Commercial Computer Software Documentation,” as such terms are used in 48 C.F.R. §12.212 or 48 C.F.R. §227.7202, as applicable. Consistent with 48 C.F.R. §12.212 or 48 C.F.R. §§227.7202-1 through
227.7202-4, as applicable, the Commercial Computer Software and Commercial Computer Software Documentation are being licensed to U.S. Government end users (a) only as Commercial Items and (b) with only those rights as are granted to all other end users pursuant to the terms and conditions herein. Unpublished-rights reserved under the copyright laws of the United States. Adobe Systems Incorporated, 345 Park Avenue, San Jose, CA 95110-2704, USA. For U.S. Government End Users, Adobe agrees to comply with all applicable equal opportunity laws including, if appropriate, the provisions of Executive Order 11246, as amended, Section 402 of the Vietnam Era Veterans Readjustment Assistance Act of 1974 (38 USC 4212), and Section 503 of the Rehabilitation Act of 1973, as amended, and the regulations at 41 CFR Parts 60-1 through 60-60, 60-250, and 60-741. The affirmative action clause and regulations contained in the preceding sentence shall be incorporated by reference.
Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
How to Use the Scripts in this Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
About the Structure of the Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
For More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2 Scripting Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Script Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Getting the Current Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Script Versioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Targeting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Interpretation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Using the do script Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Sending parameters to do script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Returning values from do script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Controlling Undo with do Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Working with Script Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Running Scripts at Startup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3 Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Basic Document Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Creating a new document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Opening a document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Saving a document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Closing a document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Basic Page Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Defining page size and document length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Defining bleed and slug areas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Setting page margins and columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Changing the appearance of the pasteboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Guides and grids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Changing measurement units and ruler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Defining and applying document presets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Setting up master spreads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Adding XMP metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Creating a document template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Creating watermarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Adjusting Page Sizes and Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Selecting pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Resizing and reframing pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Transforming pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3
4
Master page overlay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Making an Adaptive Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Making a flexible layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Adding guides for a guide-based layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Setting constraints for an object-based layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Creating alternative layouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Collecting and Dropping Content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Printing a Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Printing using page ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Setting print preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Printing with printer presets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Exporting a Document as PDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Exporting to PDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Setting PDF export options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Exporting to grayscale PDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Exporting a range of pages to PDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Exporting individual pages to PDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Exporting PDF with interactive features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Exporting as a PDF form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Exporting Pages as EPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Exporting all pages to EPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Exporting a range of pages to EPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Exporting as EPS with file naming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Exporting to EPub . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Exporting the current document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Setting EPub export options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
4 Working with Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Understanding the Layer Object Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Scripting Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Creating layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Referring to layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Deleting layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Moving layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Duplicating layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Merging layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Assigning page items to layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Setting layer properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
5 Text and Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Entering and Importing Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Creating a text frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Adding text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Stories and text frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Replacing text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Inserting special characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Placing Text and Setting Text-Import Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Exporting Text and Setting Text-Export Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
5
Understanding Text Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Working with text selections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Moving and copying text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Text objects and iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Working with Text Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Linking text frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Unlinking text frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Removing a frame from a story . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Splitting all frames in a story . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Creating an anchored frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Fitting text frames to content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Formatting Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Setting text defaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Working with fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Applying a font . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Changing text properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Changing text color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Creating and applying styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Deleting a style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Importing paragraph and character styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Finding and Changing Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
About find/change preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Finding and changing text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Finding and changing text formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Using grep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Using glyph search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Working with Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Adding Path Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Using Autocorrect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Adding Footnotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Spanning Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Setting Text Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Working with Linked Stories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Creating linked stories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Changing linked story options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Frequently asked questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
6 Working with Page Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Creating Page Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Page-item geometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Grouping Page Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Duplicating and Moving Page Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Creating compound paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Using Pathfinder operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Converting page-item shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Arranging page items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Transforming Page Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
6
Using the transform method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Working with transformation matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Coordinate spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Transformation origin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Resolving locations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Transforming points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Transforming again . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Resize and Reframe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Working with Articles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Retrieving an article list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Adding new articles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Removing an article . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Reordering articles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Adding new members to an article . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Reordering members of an article . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Removing members from an article . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
7 User Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Dialog Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Your First InDesign Dialog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Adding a User Interface to “Hello World” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Creating a More Complex User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Working with ScriptUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Creating a progress bar with ScriptUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
8 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Understanding the Event Scripting Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
About event properties and event propagation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Working with Event Listeners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Sample afterNew Event Listener . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Sample beforePrint Event Listener . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Sample Selection Event Listeners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Sample onIdle Event Listener . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
9 Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Understanding the Menu Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Localization and menu names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Running a Menu Action from a Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Adding Menus and Menu Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Menus and Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Working with scriptMenuActions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
A More Complex Menu-scripting Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
7
10 Working with Preflight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Exploring Preflight Profiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Listing preflight profiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Listing preflight rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Listing preflight data objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Importing a Preflight Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Creating a Preflight Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Adding Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Processing a Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Custom Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Available Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
ADBE_BlankPages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
ADBE_BleedSlug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
ADBE_BleedTrimHazard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
ADBE_Colorspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
ADBE_CrossReferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
ADBE_FontUsage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
ADBE_ImageColorManagement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
ADBE_ImageResolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
ADBE_PageCount . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
ADBE_PageSizeOrientation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
ADBE_ScaledGraphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
ADBE_ScaledType . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
ADBE_SmallText . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
ADBE_SpotColorSetup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
ADBE_StrokeRequirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
ADBE_TextOverrides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
ADBE_TransparencyBlending . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
11 Creating Dynamic Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Importing Movies and Sounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Creating Buttons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
Creating Multistate Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Working with Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Basic animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
TimingSettings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Animating transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Motion presets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Design options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Key frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Adding Page Transitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
12 XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
The Best Approach to Scripting XML in InDesign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Scripting XML Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
8
Setting XML preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Setting XML import preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Importing XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
Creating an XML tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Loading XML tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Saving XML tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Creating an XML element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Moving an XML element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Deleting an XML element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Duplicating an XML element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Removing items from the XML structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Creating an XML comment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Creating an XML processing instruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Working with XML attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
Working with XML stories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Exporting XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Adding XML Elements to a Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Associating XML elements with page items and text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Marking up existing layouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Applying styles to XML elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Working with XML tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
13 XML Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Why use XML rules? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
XML-rules programming model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
XML Rules Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Setting up a sample document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Getting started with XML rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Changing the XML structure using XML rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Duplicating XML elements with XML rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
XML rules and XML attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Applying multiple matching rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Finding XML elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Extracting XML elements with XML rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
Applying formatting with XML rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Creating page items with XML rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Creating Tables using XML Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Scripting the XML-rules Processor Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
14 Track Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
Tracking Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
Navigating tracked changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
Accepting and reject tracked changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
Information about tracked changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Preferences for Tracking Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
1
Chapter Update Status
CS6 Unchanged

Introduction

This document shows how to do the following:
Work with the Adobe® InDesign® scripting environment.
Use advanced scripting features.
Perform basic document tasks like setting up master spreads, printing, and exporting.
Work with page items (rectangles, ellipses, graphic lines, polygons, text frames, and groups).
Work with text and type in an InDesign document, including finding and changing text.
Create dialog boxes and other user-interface items.
Customize and add menus and create menu actions.
Respond to user-interface events.
Work with XML, from creating XML elements and importing XML to adding XML elements to a layout.
Apply XML rules, a new scripting feature that makes working with XML in InDesign faster and easier.
We assume that you have already read the Adobe InDesign Scripting Tutorial and know how to create, install, and run scripts. If you need to know how to connect with your scripting environment or view the InDesign scripting object model from your script editor, that information can be found in the Adobe InDesign Scripting Tutorial.

How to Use the Scripts in this Document

For the most part, the scripts shown in this document are not complete scripts. They are only fragments of scripts, and are intended to show only the specific part of a script relevant to the point being discussed in the text. You can copy the script lines shown in this document and paste them into your script editor, but you should not expect them to run without further editing. Note, in addition, that scripts copied out of this document may contain line breaks and other characters (due to the document layout) that will prevent them from executing properly.
A zip archive of all of the scripts shown in this document is available at the InDesign scripting home page, at: http://www.adobe.com/products/indesign/scripting/index.html expanded the archive, move the folders corresponding to the scripting language(s) of your choice into the Scripts Panel folder inside the Scripts folder in your InDesign folder. At that point, you can run the scripts from the Scripts panel inside InDesign.
. After you have downloaded and
9
CHAPTER 1: Introduction About the Structure of the Scripts 10

About the Structure of the Scripts

The script examples are all written using a common template that includes the handlers “main,” “mySetup,” “mySnippet,” and “myTeardown.” We did this to simplify automated testing and publication—there is no reason for you to construct your scripts this way. Most of the time, the part of the script you will be interested in will be inside the “mySnippet” handler.

For More Information

For more information on InDesign scripting, you also can visit the InDesign Scripting User to User forum, at
http://www.adobeforums.com
newest scripts. The forum contains hundreds of sample scripts.
. In the forum, script writers can ask questions, post answers, and share their
2
Chapter Update Status
CS6 Updated “Script Versioning” on page 12 and its three subsections have been updated, corrected, and clarified.

Scripting Features

This chapter covers scripting techniques related to InDesign’s scripting environment. Almost every other object in the InDesign scripting model controls a feature that can change a document or the application defaults. By contrast, the features in this chapter control how scripts operate.
This document discusses the following:
The script preferences object and its properties.
Getting a reference to the executing script.
Running scripts in prior versions of the scripting object model.
Using the do script method to run scripts.
Working with script labels.
Running scripts at InDesign start-up.
We assume that you have already read Adobe InDesign Scripting Tutorial and know how to write, install, and run InDesign scripts in the scripting language of your choice.

Script Preferences

The script preferences object provides objects and properties related to the way InDesign runs scripts. The following table provides more detail on each property of the script preferences object:
Property Description
enable redraw
scripts folder
scripts list
Turns screen redraw on or off while a script is running from the Scripts panel.
The path to the scripts folder.
A list of the available scripts. This property is an array of arrays, in the following form:
[[fileName, filePath], ...]
Where fileName is the name of the script file and filePath is the full path to the script. You can use this feature to check for the existence of a script in the installed set of scripts.
11
CHAPTER 2: Scripting Features Getting the Current Script 12
Property Description
user interaction level
This property controls the alerts and dialogs InDesign presents to the user. When you set this property to any alerts or dialogs. Set it to disable dialogs. Set it to alerts and dialogs. The ability to turn off alert displays is very useful when you are opening documents via script; often, InDesign displays an alert for missing fonts or linked graphics files. To avoid this alert, set the user-interaction level to then restore user interaction (set the property to completing script execution.
version
The version of the scripting environment in use. For more information, see
“Script Versioning” on page 12
version of the application.

Getting the Current Script

You can get a reference to the current script using the active script property of the application object. You can use this property to help you locate files and folders relative to the script, as shown in the following example (from the ActiveScript tutorial script):
tell application "Adobe InDesign CS6"
set myScript to active script display dialog ("The current script is: " & myScript) tell application "Finder"
set myFile to file myScript
set myParentFolder to container of myFile end tell display dialog ("The folder containing the active script is: " & myParentFolder)
end tell
never interact, InDesign does not display
interact with alerts to enable alerts but
interact with all to restore the normal display of
never interact before opening the document,
interact with all) before
. Note this property is not the same as the
When you debug scripts using a script editor, the active script property returns an error. Only scripts run from the Scripts palette appear in the

Script Versioning

InDesign can run scripts using earlier versions of the InDesign scripting object model. To run an older script in a newer version of InDesign, you must consider the following:
Targeting — Scripts must be targeted to the version of InDesign in which they are being run (i.e., the
current version). The mechanics of targeting are language specific as described in “Targeting” on
page 13.
Compilation — This involves mapping the names in the script to the underlying script IDs, which are
what InDesign understands. The mechanics of compilation are language specific as described in
“Compilation” on page 13
Interpretation — This involves matching the IDs to the appropriate request handler within InDesign
so that InDesign correctly interprets a script written for an earlier version of the scripting object model. To do this, either explicitly set the application’s script preferences to the old object model within the
active script property.
.
CHAPTER 2: Scripting Features Script Versioning 13
script (as shown in “Interpretation” on page 13) or run the script from a folder in the Scripts panel folder as follows:
Folder For InDesign version of scripts
Version 8.0 Scripts
Version 7.0 Scripts
Version 6.0 Scripts
Version 5.0 Scripts
Version 2.0 Scripts

Targ eting

A script must always target the version of InDesign under which it is running (the current version), either explicitly or implicitly. Targeting is implicit when the script is launched from the Scripts panel.
Otherwise, explicit targeting for AppleScripts is done using the tell statement:
--Target InDesign CS6 tell application "Adobe InDesign CS6"

Compilation

Typically, AppleScripts are compiled using the targeted application’s dictionary. This behavior may be overridden by means of the InDesign dictionary for compilation purposes. For example, to use a CS5 script (version 7.0) within CS6 (version 8.0):
CS6
CS5 and CS5.5
CS4
CS3
CS2
using terms from statement, which substitutes a different version of the
tell application "Adobe InDesign CS6" --target CS6
using terms from application "InDesign CS5" --compile using CS5
--InDesign CS5 version script goes here. end using terms from end tell
For this to work, you need to generate a CS5 version of the AppleScript dictionary, use the publish
terminology command, which is exposed on the application object. The dictionary is generated into a
folder (named with the version of the DOM) that is in the preferences folder. For example, to generate the CS5 dictionary into the
/Users/<username>/Library/Preferences/Adobe InDesign/Version 8.0/<locale>/Scripting Support/7.0-J folder:
tell application "Adobe InDesign CS6"
--publish the InDesign CS5 dictionary (version 7.0 DOM) publish terminology version 7.0 end tell

Interpretation

The InDesign application object contains a script preferences object, which allows a script to get/set the version of the scripting object model to use for interpreting scripts. The version defaults to the current version of the application and persists.
Scripting Support folder in your application’s
CHAPTER 2: Scripting Features Using the do script Method 14
For example, to change the version of the scripting object model to CS5 (7.0):
--Set to 7.0 scripting object model set version of script preferences to 7.0

Using the do script Method

The do script method gives a script a way to execute another script. The script can be a string of valid scripting code or a file on disk. The script can be in the same scripting language as the current script or another scripting language. The available languages vary by platform: on Mac OS
®
AppleScript or JavaScript; on Windows
The
do script method has many possible uses:
Running a script in another language that provides a feature missing in your main scripting language.
, VBScript or JavaScript.
For example, VBScript lacks the ability to display a file or folder browser, which JavaScript has. AppleScript can be very slow to compute trigonometric functions (sine and cosine), but JavaScript performs these calculations rapidly. JavaScript does not have a way to query Microsoft contents of a specific spreadsheet cell, but both AppleScript and VBScript have this capability. In all these examples, the
do script method can execute a snippet of scripting code in another language,
to overcome a limitation of the language used for the body of the script.
®
, you can run
®
Excel for the
Creating a script “on the fly.” Your script can create a script (as a string) during its execution, which it
can then execute using the
do script method. This is a great way to create a custom dialog or panel
based on the contents of the selection or the attributes of objects the script creates.
Embedding scripts in objects. Scripts can use the do script method to run scripts that were saved as
strings in the
label property of objects. Using this technique, an object can contain a script that
controls its layout properties or updates its content according to certain parameters. Scripts also can be embedded in XML elements as an attribute of the element or as the contents of an element. See
“Running Scripts at Startup” on page 18

Sending parameters to do script

To send a parameter to a script executed by do script, use the following form (from the DoScriptParameters tutorial script):
tell application "Adobe InDesign CS6"
--Create a list of parameters. set myParameters to {"Hello from do script", "Your message here."}
--Create a JavaScript as a string. set myJavaScript to "alert(\"First argument: \" + arguments[0] + \"\\rSecond argument: \" + arguments[1])"
--Run the JavaScript using the do script command. do script myJavaScript language javascript with arguments myParameters
--Create an AppleScript as a string. set myAppleScript to "tell application \"Adobe InDesign CS6\"" & return set myAppleScript to myAppleScript & "display dialog (\"First argument: \" & item 1 of arguments & return & \"Second argument: \" & item 2 of arguments)" & return set myAppleScript to myAppleScript & "end tell"
--Run the AppleScript using the do script command. do script myAppleScript language applescript language with arguments myParameters
end tell
.
CHAPTER 2: Scripting Features Using the do script Method 15

Returning values from do script

The following script fragment shows how to return a value from a script executed by do script. This example uses a JavaScript that is executed as a string, but the same method works for script files. This example returns a single value, but you can return multiple values by returning an array (for the complete script, refer to the DoScriptReturnValues script).
set myDocument to document 1 set myPage to page 1 of myDocument set myTextFrame to text frame 1 of myPage tell myDocument
set myDestinationPage to make page end tell set myPageIndex to name of myDestinationPage set myID to id of myTextFrame set myJavaScript to "var myDestinationPage = arguments[1];" & return set myJavaScript to myJavaScript & "myID = arguments[0];" & return set myJavaScript to myJavaScript & "var myX = arguments[2];" & return set myJavaScript to myJavaScript & "var myY = arguments[3];" & return set myJavaScript to myJavaScript & "var myPageItem = app.documents.item(0).pages.item(0).pageItems.itemByID(myID);" & return set myJavaScript to myJavaScript & "myPageItem.duplicate(app.documents.item(0).pages.item(myDestinationPage));" & return
--Create an array for the parameters we want to pass to the JavaScript. set myArguments to {myID, myPageIndex, 0, 0} set myDuplicate to do script myJavaScript language javascript with arguments myArguments
--myDuplicate now contains a reference to the duplicated text frame.
--Change the text in the duplicated text frame. set contents of myDuplicate to "Duplicated text frame."
Another way to get values from another script is to use the script args (short for “script arguments”) object of the application. The following script fragment shows how to do this (for the complete script, see DoScriptScriptArgs):
tell application "Adobe InDesign CS6"
--Create a string to be run as an AppleScript.
set myAppleScript to "tell application \"Adobe InDesign CS6\"" & return
set myAppleScript to myAppleScript & "tell script args" & return
set myAppleScript to myAppleScript & "set value name \"ScriptArgumentA\"
value \"This is the first AppleScript script argument value.\"" & return
set myAppleScript to myAppleScript & "set value name \"ScriptArgumentB\"
value \"This is the second AppleScript script argument value.\"" & return
set myAppleScript to myAppleScript & "end tell" & return
set myAppleScript to myAppleScript & "end tell"
--Run the AppleScript string.
do script myAppleScript language applescript language
--Retrieve the script argument values set by the script.
tell script args
set myScriptArgumentA to get value name "ScriptArgumentA" set myScriptArgumentB to get value name "ScriptArgumentB"
end tell
--Display the script argument values in a dialog box.
display dialog "ScriptArgumentA: " & myScriptArgumentA & return & "ScriptArgumentB: " & myScriptArgumentB
--Create a string to be run as a JavaScript.
CHAPTER 2: Scripting Features Controlling Undo with do Script 16
set myJavaScript to "app.scriptArgs.setValue(\"ScriptArgumentA\", \"This is the first JavaScript script argument value.\");" & return
set myJavaScript to myJavaScript & "app.scriptArgs.setValue(\"ScriptArgumentB\", \"This is the second JavaScript script argument value.\");" & return
--Run the JavaScript string.
do script myJavaScript language javascript
--Retrieve the script argument values set by the script.
tell script args
set myScriptArgumentA to get value name "ScriptArgumentA" set myScriptArgumentB to get value name "ScriptArgumentB"
end tell
--Display the script argument values in a dialog box.
display dialog "ScriptArgumentA: " & myScriptArgumentA & return & "ScriptArgumentB: " & myScriptArgumentB end tell

Controlling Undo with do Script

InDesign gives you the ability to undo almost every action, but this comes at a price: for almost every action you make, InDesign writes to disk. For normal work you using the tools presented by the user interface, this does not present any problem. For scripts, which can perform thousands of actions in the time a human being can blink, the constant disk access can be a serious drag on performance.
do script command offers a way around this performance bottleneck by providing two parameters
The that control the way that scripts are executed relative to InDesign’s Undo behavior. These parameters are shown in the following examples:
--Given a script "myAppleScript" and an array of parameters "myParameters"... tell application "Adobe InDesign CS6" do script myJavaScript language javascript with arguments myArguments undo mode fast entire script undo name "Script Action" end tell
--undo modes can be:
--auto unto: Add no events to the Undo queue.
--entire script: Put a single event in the Undo queue.
--fast entire script: Put a single event in the Undo queue.
--script request: Undo each script action as a separate event.
--The last parameter is the text that appears in the Undo menu item.

Working with Script Labels

Many objects in InDesign scripting have a label property, including page items (rectangles, ovals, groups, polygons, text frames, and graphic lines), table cells, documents, stories, and pages. This property can store a very large amount of text.
The label of page items can be viewed, entered, or edited using the Script Label panel (choose Window > Utilities > Script Label to display this panel), shown below. You also can add a label to an object using scripting, and you can read the script label via scripting. For many objects, like stories, pages, and paragraph styles, you cannot set or view the label using the Script Label panel.
CHAPTER 2: Scripting Features Working with Script Labels 17
The label property can contain any form of text data, such as tab- or comma-delimited text, HTML, or XML. Because scripts also are text, they can be stored in the
label property.
Page items can be referred to by their layers) can be referred to by their
label, just like named items (such as paragraph styles, colors, or
name. The following script fragment demonstrates this special case of the
label property (for the complete script, see ScriptLabel):
set myDocument to make document set myPage to page 1 of myDocument set myPageWidth to page width of document preferences of myDocument set myPageHeight to page height of document preferences of myDocument
--Create 10 random page items. repeat with i from 1 to 10
set myX1 to my myGetRandom(0, myPageWidth, false)
set myY1 to my myGetRandom(0, myPageHeight, false)
set myX2 to my myGetRandom(0, myPageWidth, false)
set myY2 to my myGetRandom(0, myPageHeight, false)
tell myPage
set myRectangle to make rectangle with properties {geometric bounds:{myY1, myX1,
myY2, myX2}}
end tell
if my myGetRandom(0, 1, true) = 1 then
set label of myRectangle to "myScriptLabel"
end if end repeat set myCount to 0 repeat with i from 1 to count of page items of myPage
if label of page item i of myPage is "myScriptLabel" then
set myCount to myCount + 1
end if end repeat display dialog ("Found " & myCount & " page items with the label.")
--This function gets a random number in the range myStart to myEnd. on myGetRandom(myStart, myEnd, myInteger)
set myRange to myEnd - myStart
if myInteger = true then
set myRandom to myStart + (random number from myStart to myEnd)
else
set myRandom to myStart + (random number from myStart to myEnd) as integer end if return myRandom
end myGetRandom
In addition, all objects that support the label property also support custom labels. A script can set a custom label using the
insert label method, and extract the custom label using the extract label
method, as shown in the following script fragment (from the CustomLabel tutorial script):
CHAPTER 2: Scripting Features Running Scripts at Startup 18
tell application "Adobe InDesign CS6"
set myDocument to make document tell view preferences of myDocument
set horizontal measurement units to points
set vertical measurement units to points end tell set myPage to page 1 of myDocument tell myPage
set myRectangle to make rectangle with properties
{geometric bounds:{72, 72, 144, 144}}
--Insert a custom label using insert label. The first parameter is the
--name of the label, the second is the text to add to the label.
tell myRectangle
insert label key "CustomLabel" value "This is some text stored in a custom label."
--Extract the text from the label and display it in an alert.
set myString to extract label key "CustomLabel" end tell display dialog ("Custom label contained: " & myString)
end tell
end tell

Running Scripts at Startup

To run a script when InDesign starts, put the script in the Startup Scripts folder in the Scripts folder (for more information, see “Installing Scripts” in Adobe InDesign Scripting Tutorial).
3
Chapter Update Status
CS6 Changes • Updated list of what this chapter shows you how to do.
•Added section “Making an Adaptive Layout” on page 43
.
•Added section “Collecting and Dropping Content” on page 46
.
• Added subsection “Exporting to grayscale PDF” on page 53
.
• Added subsection “Exporting as a PDF form” on page 56
.
•In “Adjusting Page Sizes and Layout” on page 41
, “Resizing and reframing pages” on page 41, and “Transforming pages” on
page 42, removed outdated references to features being new in CS5.

Documents

The work you do in InDesign revolves around documents—creating them, saving them, printing or exporting them, and populating them with page items, colors, styles, and text. Almost every document-related task can be automated using InDesign scripting.
This chapter shows you how to do the following
Perform basic document-management tasks, including:
Creating a new document.
Opening a document.
Saving a document.
Closing a document.
Perform basic page-layout operations, including:
Setting the page size and document length.
Defining bleed and slug areas.
Specifying page columns and margins.
Change the appearance of the pasteboard.
Use guides and grids.
Change measurement units and ruler origin.
Define and apply document presets.
Set up master pages (master spreads)
Set text-formatting defaults.
Add XMP metadata (information about a file).
Create a document template.
Create watermarks.
19
CHAPTER 3: Documents Basic Document Operations 20
Apply different sizes to different pages (multiple page sizes).
Apply flexible layout formats to the same pages for use in different devices or documents with
different sizes or orientation.
Print a document.
Export a document as Adobe PDF.
Export pages of a document as EPS.
Export a document as an ePub file.
We assume that you have already read Adobe InDesign Scripting Tutorial and know how to create, install, and run a script.

Basic Document Operations

Opening, closing, and saving documents are some of the most basic document tasks. This section shows how to do them using scripting.

Creating a new document

The following script shows how to make a new document using scripting. (For the complete script, see MakeDocument.)
tell application "Adobe InDesign CS6"
set myDocument to make document
end tell
To create a document using a document preset, the make command includes an optional parameter you can use to specify a document preset, as shown in the following script. (For the complete script, see MakeDocumentWithPreset.)
tell application "Adobe InDesign CS6"
--Replace "myDocumentPreset" in the following line with the name
--of the document preset you want to use. set myDocument to make document with properties {document preset:"myDocumentPreset"}
end tell
You can create a document without displaying it in a window, as shown in the following script fragment (from the MakeDocumentWithParameters tutorial script):
--Creates a new document without showing the document window.
--The "showing window" parameter controls the visibility of the document.
--Hidden documents are not minimized, and will not appear until
--you tell the document to create a new window. tell application "Adobe InDesign CS6"
set myDocument to make document with properties {showing window:false}
--To show the window:
--tell myDocument
--set myWindow to make window
--end tell
end tell
Some script operations are much faster when the document window is hidden.
CHAPTER 3: Documents Basic Document Operations 21

Opening a document

The following script shows how to open an existing document. (For the complete script, see OpenDocument.)
tell application "Adobe InDesign CS6"
--You'll have to fill in your own file path. set myDocument to open "yukino:myTestDocument.indd"
end tell
You can choose to prevent the document from displaying (that is, hide it) by setting the showing window parameter of the performance of a script. To show a hidden document, create a new window, as shown in the following script fragment (from the OpenDocumentInBackground tutorial script):
tell application "Adobe InDesign CS6"
--You can use the "showing window" parameter to open files
--without displaying them. This can speed up many scripting
--operations, and makes it possible for a script to operate
--on a file in the background. To display a document you've
--opened this way, tell the document to create a new window.
--You'll have to fill in your own file path. set myDocument to open "yukino:myTestDocument.indd" <lb> without showing window
--At this point, your script could change or get information
--from the hidden document. Once you've done that, you can show
--the document window: tell myDocument to make window
end tell
open command to false (the default is true). You might want to do this to improve

Saving a document

In the InDesign user interface, you save a file by choosing File > Save, and you save a file to another file name by choosing File > Save As. In InDesign scripting, the shown in the following script fragment (from the SaveDocument tutorial script):
--Saves the active document.
--If the active document has been changed since it was last saved, save it. tell application "Adobe InDesign CS6"
if modified of active document is true then
tell active document to save
end if
end tell
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, as shown in the following script
( fragment (from the SaveDocumentAs tutorial script):
--If the active document has not been saved (ever), save it. tell application "Adobe InDesign CS6"
if saved of active document is false then
--If you do not provide a file name, InDesign displays the Save dialog box. tell active document to save saving in "yukino:myTestDocument.indd"
end if
end tell
You can save a document as a template, as shown in the following script fragment (from the SaveAsTemplate tutorial script):
save command can do either operation, as
CHAPTER 3: Documents Basic Document Operations 22
--Save the active document as a template. tell application "Adobe InDesign CS6"
set myDocument to active document tell myDocument
if saved is true then
--Convert the file name to a string.
set myFileName to full name
set myFileName to my myReplace(myFileName, ".indd", ".indt") else
--If the document has not been saved, then give it a default file
--name/file path. You'll have to fill in the file path.
set myFileName to "yukino:myTestDocument.indt" end if save to myFileName with stationery
end tell end tell on myReplace(myString, myFindString, myChangeString)
set AppleScript's text item delimiters to myFindString
set myTextList to every text item of (myString as text)
set AppleScript's text item delimiters to myChangeString
set myString to myTextList as string
set AppleScript's text item delimiters to ""
return myString end myReplace

Closing a document

The close command closes a document, as shown in the following script fragment (from the CloseDocument tutorial script):
tell application "Adobe InDesign CS6"
close document 1
--document 1 always refers to the front-most document.
--Note that you could also use:
--close active document
end tell
The close command can take up to two optional parameters, as shown in the following script fragment (from the CloseWithParameters tutorial script):
tell application "Adobe InDesign CS6"
--Use "saving yes" to save the document,
--or "saving no" to close the document without saving,
--or "saving ask" to display a prompt. If you use
--"saving yes",you'll need to provide a reference
--to a file to save to in the second parameter (saving in).
--If the file has never been saved (it's an untitled file),
--display a prompt.
if saved of active document is not equal to true then
close active document saving ask
--Or, to save to a specific file name
--(you'll have to fill in the file path):
--set myFile to "yukino:myTestDocument.indd"
--close active document saving yes saving in myFile
else
--If the file has already been saved to a file, save it. close active document saving yes
end if end tell
CHAPTER 3: Documents Basic Page Layout 23
You can close all open documents without saving them, as shown in the following script fragment (from the CloseAll tutorial script):
tell application "Adobe InDesign CS6"
tell documents to close without saving end tell

Basic Page Layout

Each document has a default page size, assigned number of pages, bleed and slug working areas, and columns and margins to define the area into which material is placed. Again, all these parameters are accessible to scripting, as shown in the examples in this section.

Defining page size and document length

When you create a new document using the InDesign user interface, you can specify the default page size, number of pages, page orientation, and whether the document uses facing pages. To create a document using InDesign scripting, use the creating a document, you can use the the following script fragment (from the DocumentPreferences tutorial script):
make document command, which does not specify these settings. After
document preferences object to control the settings, as shown in
tell application "Adobe InDesign CS6"
set myDocument to make document
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. You can set the application defaults for page height, page width, and other properties by changing the properties of this object. You can also set individual page sizes; see “Adjusting Page Sizes and Layout”

Defining bleed and slug areas

Within InDesign, a bleed or a slug is an area outside the page margins that can be printed or included in an exported PDF. Typically, these areas are used for objects that extend beyond the page edges (bleed) and job/document information (slug). The two areas can be printed and exported independently; for example, you might want to omit slug information for the final printing of a document. The following script shows how to set up the bleed and slug for a new document. (For the complete script, see BleedAndSlug.)
.
CHAPTER 3: Documents Basic Page Layout 24
tell application "Adobe InDesign CS6"
--Create a new document.
set myDocument to make document
--The bleed and slug properties belong to the document preferences object.
tell document preferences of myDocument
--Bleed set document bleed bottom offset to "3p" set document bleed top offset to "3p" set document bleed inside or left offset to "3p" set document bleed outside or right offset to "3p"
--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 end tell
Alternately, if all the bleed distances are equal, as in the preceding example, you can use the document
bleed uniform size property, as shown in the following script fragment (from the UniformBleed tutorial
script):
tell application "Adobe InDesign CS6"
--Create a new document.
set myDocument to make document
--The bleed properties belong to the document preferences object.
tell document preferences of myDocument
--Bleed set document bleed top offset to "3p" set document bleed uniform size to true
end tell end tell
If all the slug distances are equal, you can use the document slug uniform size property, as shown in the following script fragment (from the UniformSlug tutorial script):
tell application "Adobe InDesign CS6"
--Create a new document.
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"
end tell end tell
In addition to setting the bleed and slug widths and heights, you can control the color used to draw the guides defining the bleed and slug. This property is not in the
pasteboard preferences object, as shown in the following script fragment (from the
in the
document preferences object; instead, it is
BleedSlugGuideColors tutorial script):
CHAPTER 3: Documents Basic Page Layout 25
tell application "Adobe InDesign CS6"
--Assumes you have a document open.
tell pasteboard preferences of active document
--Any of InDesign's guides can use the UIColors constants... set bleed guide color to cute teal set slug guide color to charcoal
--...or you can specify a list of RGB values
--(with values from 0 to 255) set bleed guide color to {0, 198, 192} set slug guide color to {192, 192, 192}
end tell end tell

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 new document, then sets the margins and columns for all pages in the master spread. (For the complete script, see PageMargins.)
tell application "Adobe InDesign CS6"
set myDocument to make document
tell view preferences of myDocument
set horizontal measurement units to points
set vertical measurement units to points end tell tell master spread 1 of myDocument
tell margin preferences of pages
set top to 36 set left to 36 set bottom to 48 set right to 36
end tell end tell
end tell
margin preferences object for each page. This following sample script creates a
To set the page margins for an individual page, use the margin preferences for that page, as shown in the following script fragment (from the PageMarginsForOnePage tutorial script):
tell application "Adobe InDesign CS6"
set myDocument to make document tell view preferences of myDocument
set horizontal measurement units to points
set vertical measurement units to points end tell tell margin preferences of page 1 of myDocument
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 left and right page margins, and the height of the page must be greater than the sum of the top and bottom margins. If you are creating very small pages (for example, for individual newspaper advertisements) using the InDesign user interface, you can
CHAPTER 3: Documents Basic Page Layout 26
easily set the correct margin sizes as you create the document, by entering new values in the document default page Margin fields in the New Document dialog box.
From scripting, however, the solution is not as clear: when you create a document, it uses the application’s default-margin preferences. These margins are applied to all pages of the document, including master pages. Setting the document margin preferences affects only new pages and has no effect on existing pages. If you try to set the page height and page width to values smaller than the sum of the corresponding margins on any existing pages, InDesign does not change the page size.
There are two solutions. The first is to set the margins of the existing pages before you try to change the page size, as shown in the following script fragment (from the PageMarginsForSmallPages tutorial script):
tell application "Adobe InDesign CS6"
set myDocument to make document tell margin preferences of page 1 of myDocument
set top to 0
set left to 0
set bottom to 0
set right to 0 end tell tell master spread 1 of myDocument
tell margin preferences of pages
set top to 0 set left to 0 set bottom to 0 set right to 0
end tell end tell
--At this point, you can set your page size to a small width
--and height (1x1 picas minimum). set page height of document preferences of myDocument to "1p" set page width of document preferences of myDocument to "6p"
end tell
Alternately, you can change the application’s default-margin preferences before you create the document, as shown in the following script fragment (from the ApplicationPageMargins tutorial script):
CHAPTER 3: Documents Basic Page Layout 27
tell application "Adobe InDesign CS6"
tell margin preferences
--Save the current application default margin preferences.
set myY1 to top
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
set right to 0 end tell
--At this point, you can create a new document. set myDocument to make document
--At this point, you can set your page size to a small width and height
--(1x1 picas minimum). set page height of document preferences of myDocument to "1p" set page width of document preferences of myDocument to "1p"
--Reset the application default margin preferences to their former state. tell margin preferences
set top to myY1
set left to myX1
set bottom to myY2
set right to myX2 end tell
end tell

Changing the appearance of the pasteboard

The pasteboard is the area that surrounds InDesign pages and spreads. You can use it for temporary storage of page items or for job-tracking information. You can change the size of the pasteboard and its color using scripting. The
preview background color property sets the color of the pasteboard in Preview
mode, as shown in the following script fragment (from the PasteboardPreferences tutorial script):
tell application "Adobe InDesign CS6"
set myDocument to make document tell pasteboard preferences of myDocument
--You can use either a number or a measurement string to set the
--space above/below.
set minimum space above and below to "12p"
--You can set the pasteboard background color to any
--of the predefined UIColor constants...
set preview background color to gray
--...or you can specify an array of RGB values
--(with values from 0 to 255)
--set preview Background Color to {192, 192, 192}
end tell
end tell

Guides and grids

Guides and grids make it easy to position objects on your document pages. These are very useful items to add when you are creating templates for others to use.
CHAPTER 3: Documents Basic Page Layout 28
Defining guides
Guides in InDesign give you an easy way to position objects on the pages of your document. The following script fragment shows how to use guides. (For the complete script, see Guides.)
tell application "Adobe InDesign CS6"
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 tell page 1 of myDocument
set myMarginPreferences to margin preferences
--Place guides at the margins of the page.
make guide with properties {orientation:vertical,
location:left of myMarginPreferences}
make guide with properties {orientation:vertical,
location:(myPageWidth - (right of myMarginPreferences))}
make guide with properties {orientation:horizontal,
location:top of myMarginPreferences}
make guide with properties {orientation:horizontal,
location:(myPageHeight - (bottom of myMarginPreferences))}
--Place a guide at the vertical center of the page.
make guide with properties {orientation:vertical,
location:(myPageWidth / 2)}
--Place a guide at the horizontal center of the page.
make guide with properties {orientation:horizontal,
location:(myPageHeight / 2)} end tell
end tell
Horizontal guides can be limited to a given page or extend across all pages in a spread. From InDesign scripting, you can control this using the
fit to page property. This property is ignored by vertical guides.
You can use scripting to change the layer, color, and visibility of guides, just as you can from the user interface, as shown in the following script fragment (from the GuideOptions tutorial script):
CHAPTER 3: Documents Basic Page Layout 29
tell application "Adobe InDesign CS6"
set myDocument to make document tell myDocument
--Create a layer named "guide layer".
set myLayer to make layer with properties {name:"guide layer"}
--Add a series of guides to page 1.
tell page 1
--Create a guide on the layer we created above. make guide with properties {orientation:horizontal, <lb> location:"12p", item layer:myLayer} make guide with properties {item layer:myLayer, <lb> orientation:horizontal, location:"14p"}
--Make a locked guide. make guide with properties {locked:true, <lb> orientation:horizontal, location:"16p"}
--Set the view threshold of a guide. make guide with properties {view threshold:100, <lb> orientation:horizontal, location:"18p"}
--Set the guide color of a guide using a UIColors constant. make guide with properties {guide color:gray, <lb> orientation:horizontal, location:"20p"}
--Set the guide color of a guide using an RGB array. make guide with properties {guide color:{192, 192, 192}, <lb> orientation:horizontal, location:"22p"}
end tell end tell
end tell
You also can create guides using the create guides command on spreads and master spreads, as shown in the following script fragment (from the CreateGuides tutorial script):
tell application "Adobe InDesign CS6"
set myDocument to make document tell spread 1 of myDocument
--Parameters (all optional): row count, column count, row gutter,
--column gutter, guide color, fit margins, remove existing, layer.
--Note that the create guides command does not take an RGB
--array for the guide color parameter.
create guides number of rows 4 number of columns 4 row gutter "1p" <lb>
column gutter "1p" guide color gray with fit margins and remove existing end tell
end tell
Setting grid preferences
To control the properties of the document and baseline grid, you set the properties of the grid
preferences object, as shown in the following script fragment (from the DocumentAndBaselineGrid
tutorial script):
CHAPTER 3: Documents Basic Page Layout 30
tell application "Adobe InDesign CS6"
set myDocument to make document set horizontal measurement units of view preferences of myDocument to points set vertical measurement units of view preferences of myDocument to points tell grid preferences of myDocument
set baseline start to 56
set baseline division to 14
set baseline grid shown to true
set horizontal gridline division to 14
set horizontal grid subdivision to 5
set vertical gridline division to 14
set vertical grid subdivision to 5
set document grid shown to true end tell
end tell
Snapping to guides and grids
All snap settings for a document’s grids and guides are in the properties of the guide preferences and
grid preferences objects. The following script fragment shows how to set guide and grid snap
properties. (For the complete script, see GuideGridPreferences.)
tell application "Adobe InDesign CS6"
set myDocument to active document tell guide preferences of myDocument
set guides in back to true
set guides locked to false
set guides shown to true
set guides snapto to true end tell tell grid preferences of myDocument
set document grid shown to false
set document grid snapto to true
--Objects "snap" to the baseline grid when guidePreferences.guideSnapTo
--is set to true.
set baseline grid shown to true end tell
end tell

Changing measurement units and ruler

Thus far, the sample scripts used measurement strings, strings that force InDesign to use a specific measurement unit (for example, “8.5i” for 8.5 inches). They do this because you might be using a different measurement system when you run the script.
To specify the measurement system used in a script, use the document’s shown in the following script fragment (from the ViewPreferences tutorial script):
view preferences object, as
Loading...
+ 214 hidden pages