Adobe InDesign CS4 Scripting Tutorial
1. Enter the following JavaScript in a new text file:
//Improved Hello World!
//Enter the name of a font on your system, if necessary.
try{
myFont = app.fonts.item("Arial");
}
catch (myError){};
var myDocument = app.documents.item(0);
with(myDocument){
var myPage = pages.item(0);
var myBounds = myGetBounds(myPage,myDocument);
with(myDocument.pages.item(0)){
}
}
//myGetBounds is a function that returns the bounds
//of the "live area" of a page.
function myGetBounds(myDocument, myPage){
var myPageWidth = myDocument.documentPreferences.pageWidth;
var myPageHeight = myDocument.documentPreferences.pageHeight
if(myPage.side == PageSideOptions.leftHand){
}
else{
}
var myY1 = myPage.marginPreferences.top;
var myX2 = myPageWidth - myX2;
var myY2 = myPageHeight - myPage.marginPreferences.bottom;
return [myY1, myX1, myY2, myX2];
}
2. Save the script as a plain text file with the file extension
scripts" on page
Once you've opened or created the script file, you can run the script from the ExtendScript Toolkit or from
the InDesign Scripts panel.
VBScript
Make sure you have the Hello World document open—this script relies on objects we created in that
script. If you closed the document without saving it, simply run the
a new document.
//Get a reference to the text frame.
var myTextFrame = textFrames.item(0);
//Change the size of the text frame.
myTextFrame.geometricBounds = myBounds;
var myParagraph = myTextFrame.paragraphs.item(0);
myParagraph.appliedFont = myFont;
myParagraph.justification = Justification.centerAlign;
myParagraph.pointSize = 48;
var myX2 = myPage.marginPreferences.left;
var myX1 = myPage.marginPreferences.right;
var myX1 = myPage.marginPreferences.left;
var myX2 = myPage.marginPreferences.right;
6).
Adding features to "Hello World" 27
in the Scripts Panel folder (see
.jsx
HelloWorld.vbs
"Installing
script again to make