Reply To: Script to add a Paragraph Style to text

#117083

Here is a useful variant: save this single line as “apply-YourStyle.jsx” and it will apply the style “YourStyle”. Save it as “apply-somethingElse.jsx” and it will apply “somethingElse” – the name of the style gets taken from the script name! So you can copy the script as many times as you like, and you only have to change its file name.

app.selection[0].applyParagraphStyle(app.documents[0].paragraphStyles.itemByName(app.activeScript.name.match(/apply-(.+)\.jsx?/)[1].replace(/%20/g, ' ')));

Do note, however, that this only works with very basic style names, containing simple filename characters only. That is, you cannot make it work with an overly fancy style name such as “Header 1 + line above (when not at top of page)”, nor does it work with Style Groups. Having spaces in the style name should be okay, though.

This article was last modified on June 7, 2019

Comments (0)

Loading comments...