Adobe InDesign CS4 Scripting Tutorial
Constructing a document
38
Adding and applying a paragraph style
Our headline looks plain, so we will format it using a paragraph style. To do that, we must create the
paragraph style. The following diagram shows the objects and properties we will work with (again, the text
in this diagram uses the JavaScript form of the scripting terms):
AppleScript
--First, check to see if the paragraph style already exists.
try
set myParagraphStyle to paragraph style "Heading 1" of myDocument
on error
--The paragraph style did not exist, so create it.
tell 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 color "Red" of myDocument
on error
--The color did not exist, so create it.
tell myDocument
set myColor to make color with properties {name:"Red", model:process,
color value:{0, 100, 100, 0}}
end tell
end try
--Now set the formatting of the paragraph style.
try
set applied font of myParagraphStyle to "Arial"
set font style of myParagraphStyle to "Bold"
end try
set point size of myParagraphStyle to 24
set space after of myParagraphStyle to 24
set space before of myParagraphStyle to 24
appliedFont
pointSize
spaceBefore
spaceAfter
fillColor
document
paragraphStyle
paragraphStyles
fontStyle