Copy link to clipboard
Copied
I'm having a little trouble understanding how to script the creation of a new paragraph style and define its justification settings at the same time. This example makes sense:
app.activeDocument.paragraphStyles.add(name:"New Style", appliedFont:"Arial\tRegular", pointSize:"12pt")
but how do I make that paragraph, say, center align? Currently I do it as 2 steps: Create the style as above and them modify the style properties, like:
app.activeDocument.paragraphStyles.itemByName("New Style").properties = {justification: Justification.CENTER_ALIGN}
Is there a way to do it in one step?
Thanks!
1 Correct answer
Hi Dan,
The add() method of ParagraphStyles has a single optional argument called 'withProperties" which is expecting an object—something in braces {} with key: value pairs seperated by commas. So:
app.activeDocument.paragraphStyles.add({
name: "New Style",
appliedFont: "Arial\tRegular",
pointSize: "12pt",
justification: Justification.CENTER_ALIGN
})
- Mark
Copy link to clipboard
Copied
Hi Dan,
The add() method of ParagraphStyles has a single optional argument called 'withProperties" which is expecting an object—something in braces {} with key: value pairs seperated by commas. So:
app.activeDocument.paragraphStyles.add({
name: "New Style",
appliedFont: "Arial\tRegular",
pointSize: "12pt",
justification: Justification.CENTER_ALIGN
})
- Mark
Copy link to clipboard
Copied
Thanks, Mark. I dunno what I was missing that didn't work for me yesterday, but it works now!
Copy link to clipboard
Copied
Maybe accidentally left out the braces {} as per example in your post? Most errors I get writing scripts are simple typos.
- Mark

