Copy link to clipboard
Copied
Hello i'am looking for a script that find for example a paragraph style 'Header' and change that to paragraph style 'Header 2'
Can somebody help me?
Kind regards,
Patrick
One more time. Sorry, not enough coffee today:
var allPars = app.activeDocument.textFrames.everyItem().paragraphs.everyItem().getElements();
alert(allPars.length);
for (var i = 0; i < allPars.length; i++) {
if (allPars[i].appliedParagraphStyle.name == "Header") {
allPars[i].appliedParagraphStyle = "Header 2";
}
}
If you want to find and change more paragraph styles, you can add additional if statements within the loop using the same structure as above. There are other ways to, like
...Copy link to clipboard
Copied
If you're not aware, you can use Find/Replace using the Find Format and Change Format in InDesign itself:
Otherwise, you'll need to specify how you're finding your paragraphs in your script. Here's one that would iterate through every paragraph in the doc and check, but it's not very efficient.
var allPars = app.activeDocument.textFrames.everyItem().paragraphs.everyItem().getElements();
alert(allPars.length);
for (var i = 0; i < allPars.length; i++) {
if (allPars[i].appliedParagraphStyle.name == "Header") {
allPars[i].appliedParagraphStyle = "Header 2";
}
}
Copy link to clipboard
Copied
The cript above is not working.
I have more paragraph styles. Is there also i way with find/change by list that i can change the txt file.
For example:
Copy link to clipboard
Copied
Oops, made a quick fix. Try again.
Copy link to clipboard
Copied
Where can i find the fix?
Copy link to clipboard
Copied
In the original code, repasted here:
var allPars = app.activeDocument.textFrames.everyItem().paragraphs.everyItem().getElements();
alert(allPars.length);
for (var i = 0; i < allPars.length; i++) {
if (allPars[i].appliedParagraphStyle.name == "Header") {
allPars[i].appliedParagraphStyle = "Header 2";
}
}
Copy link to clipboard
Copied
It's still not working. The script change nothing.
Copy link to clipboard
Copied
One more time. Sorry, not enough coffee today:
var allPars = app.activeDocument.textFrames.everyItem().paragraphs.everyItem().getElements();
alert(allPars.length);
for (var i = 0; i < allPars.length; i++) {
if (allPars[i].appliedParagraphStyle.name == "Header") {
allPars[i].appliedParagraphStyle = "Header 2";
}
}
If you want to find and change more paragraph styles, you can add additional if statements within the loop using the same structure as above. There are other ways to, like using Find/Replace scripting or modifying Find Change By List.
Copy link to clipboard
Copied
Hi,
Were you aware that you can do this manually in the paragraph styles menu? When you delete a style you have the option of replacing it with another. Just make sure the new style is not based on the original style. Here is how you would do it with AppleScript:
tell application "Adobe InDesign 2020"
tell document 1
set oldStyle to paragraph style "Header"
set newStyle to paragraph style "Header2"
delete oldStyle replacing with newStyle
end tell
end tell
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more