background image

ADOBE

®

 INDESIGN

®

 CS4

ADOBE INDESIGN CS4

SCRIPTING TUTORIAL

Summary of Contents for 65024872 - InDesign CS4 - Mac

Page 1: ...ADOBE INDESIGN CS4 ADOBE INDESIGN CS4 SCRIPTING TUTORIAL...

Page 2: ...ator and Photoshop are registered trademarks or trademarks of Adobe Systems Incorporated in the United States and or other countries Microsoft and Windows are registered trademarks or trademarks of Mi...

Page 3: ...InDesign script 9 AppleScript 9 JavaScript 9 VBScript 9 Walking through the script 10 Scripting and the InDesign object model 11 Scripting terminology 11 Comments 11 Values 11 Variables 13 Operators 1...

Page 4: ...3 AppleScript 34 JavaScript 34 VBScript 35 Adding master text frames 35 AppleScript 36 JavaScript 36 VBScript 36 Overriding master page items and adding text 37 AppleScript 37 JavaScript 37 VBScript 3...

Page 5: ...There even are a few things you can do in scripting that you cannot do using the user interface Scripts can create menus add menu items create and display dialog boxes and panels and respond to user i...

Page 6: ...s like dialog boxes or panels and display alerts if necessary Using the scripts panel The InDesign Scripts panel is the easiest and best way to run most InDesign scripts If the panel is not already vi...

Page 7: ...eatures of JavaScript 1 5 are supported Adobe Illustrator Adobe Photoshop and other Adobe Creative Suite products also use the ExtendScript JavaScript interpreter While you can write scripts using oth...

Page 8: ...ny or all those scripting languages NOTE You also can use almost any other programming language like Python or C that can connect to the platform standard automation system that is beyond the scope of...

Page 9: ...see Installing scripts on page 6 To run the script double click the script name in the Scripts panel or click the Run button in the Script Editor window JavaScript Start the ExtendScript Toolkit or a...

Page 10: ...eference to the text frame AppleScript tell page 1 of myDocument set myTextFrame to make text frame JavaScript var myTextFrame myDocument pages item 0 textFrames add VBScript Set myTextFrame myDocumen...

Page 11: ...In VBScript type Rem for remark or a single straight quote to the left of the comment Type the comment marker at the beginning of a line to make the entire line a comment In JavaScript type to the lef...

Page 12: ...Number 2 myString myNumber To convert from a string to an integer myString 2 myNumber parseInt myString If your string contains a decimal value use parseFloat rather than parseInt myNumber parseFloat...

Page 13: ...ing a value to a variable Assigning values or strings to variables is fairly simple as shown in the following table NOTE In JavaScript all variables not preceded by var are considered global by defaul...

Page 14: ...g table Finding the value type of a variable Sometimes your scripts must make decisions based on the value type of an object For example if you are working on a script that operates on a text selectio...

Page 15: ...the following string Pride and Prejudice In JavaScript use the plus sign to join the two strings Pride and Prejudice returns the string Pride and Prejudice Conditional statements If the selected obje...

Page 16: ...and they are what we work with when we write InDesign scripts Objects in your publication are arranged in a specific order frames are on pages which are inside a document which is inside the InDesign...

Page 17: ...or example finding and changing text copying the selection creating new documents and opening libraries Application preferences For example text preferences PDF export preferences and document prefere...

Page 18: ...ment events Events that occur at the document level like importing text See application events in this table Document methods The actions the document can take for example closing a document printing...

Page 19: ...le Script Editor 3 In the Script Editor choose File Open Dictionary The Script Editor displays a list of scriptable applica tions 4 Select your copy of InDesign and click OK The Script Editor displays...

Page 20: ...and Methods list The ExtendScript toolkit displays more information on the property or method you selected For more information on using the ExtendScript Toolkit Object Model Viewer see the Creative S...

Page 21: ...click Browse and locate and select the file Resources for Visual Basic tlb which is usually inside Documents and Settings user_name Application Data Adobe InDesign Version 6 0 Scripting Support where...

Page 22: ...te and select the Resources for Visual tlb file which usually is in Documents and Settings user_name Application Data Adobe InDesign Version 6 0 Scripting Support where user_name is your user name Onc...

Page 23: ...list of available references click Browse and locate and select the Resources for Visual Basic tlb file which usually is in Documents and Settings user_name Application Data Adobe InDesign Version 6...

Page 24: ...of the object s bounding box or y1 x1 y2 x2 Working with measurement units When you send measurement values to InDesign you can send numbers for example 14 65 or measurement strings for example 1p7 1...

Page 25: ...t without saving it simply run the HelloWorld applescript script again to make a new document Either open the ImprovedHelloWorld applescript tutorial script or perform the following steps to create th...

Page 26: ...de of myPage is left hand then set myX2 to left set myX1 to right else set myX1 to left set myX2 to right end if set myY1 to top set myY2 to bottom end tell set myX2 to myPageWidth myX2 set myY2 to my...

Page 27: ...Bounds myDocument myPage var myPageWidth myDocument documentPreferences pageWidth var myPageHeight myDocument documentPreferences pageHeight if myPage side PageSideOptions leftHand var myX2 myPage mar...

Page 28: ...size and alignment If TypeName myFont Nothing Then myParagraph AppliedFont myFont End If myParagraph PointSize 48 myParagraph Justification idJustification idCenterAlign Rem myGetBounds is a function...

Page 29: ...eak the script up into a series of blocks each block demonstrates a specific area or task in InDesign scripting NOTE The figure above uses the JavaScript version of the scripting terms For AppleScript...

Page 30: ...editor for the language of your choice if you d like to follow along baselineColor baselineStart baselineGridRelativeOption baselineDivision baselineViewThreshold gridColor verticalGridlineDivision h...

Page 31: ...m to 78 set column count to 3 set column gutter to 14 end tell Page margins and columns for the right hand page tell margin preferences of page 2 of myMasterSpread set left to 84 set top to 70 set rig...

Page 32: ...reference to the first master spread Set myMasterSpread myDocument MasterSpreads Item 1 Rem Get a reference to the margin preferences of the first page in the master spread Set myMarginPreferences myM...

Page 33: ...ridPreferences BaselineDivision 14 myGridPreferences BaselineStart 70 myGridPreferences BaselineGridShown True Adding master page items Next we add two text frames to the master pages These frames wil...

Page 34: ...er to 11 set leading of character 1 of myRightFooter to 14 set justification of character 1 of myRightFooter to right align end tell JavaScript var myMasterSpread myDocument masterSpreads item 0 var m...

Page 35: ...age TextFrames Add myRightFooter GeometricBounds Array 728 84 742 542 myRightFooter TextFramePreferences FirstBaselineOffset idFirstBaseline idLeadingOffset myRightFooter Contents idSpecialCharacters...

Page 36: ...to myRightTextFrame JavaScript var myLeftPage myMasterSpread pages item 0 var myRightPage myMasterSpread pages item 1 var myLeftTextFrame myLeftPage textFrames add myLeftTextFrame geometricBounds 70 7...

Page 37: ...ext frames we created and add text to it AppleScript tell text frame 1 of page 2 of master spread 1 of myDocument set myTextFrame to override destination page page 1 of myDocument end tell Add text by...

Page 38: ...ll myDocument set myParagraphStyle to make paragraph style with properties name Heading 1 end tell end try We ll need to create a color Check to see if the color already exists try set myColor to colo...

Page 39: ...ue 0 100 100 0 Now set the formatting of the paragraph style myParagraphStyle appliedFont Arial myParagraphStyle fontStyle Bold myParagraphStyle pointSize 24 myParagraphStyle spaceAfter 24 myParagraph...

Page 40: ...tem 1 paragraphs item 1 appliedParagraphStyle myParagraphStyle Placing a text file Next we import a text file We add the text after the headline in the first text frame on the first page The script di...

Page 41: ...o get a reference to the frame use the parent property of the graphic Once we have that reference we can apply an object style to the frame AppleScript Display a standard open file dialog box to selec...

Page 42: ...if you didn t press Cancel place the graphic file on the page if myGraphicFile myGraphicFile null var myGraphic myDocument pages item 0 place myGraphicFile Since you can place multiple graphics at on...

Page 43: ...a string myJavaScriptString var myTextFile File openDialog Choose a graphic file myTextFile fsName Rem Run the JavaScript using DoScript myGraphicFileName myInDesign DoScript myJavaScriptString idScr...

Page 44: ...have learned the basics of InDesign scripting In each example we created objects set object properties and used object methods For your next step in learning about InDesign scripting see the Adobe InD...

Reviews: