Skip to main content
Inspiring
November 15, 2023
Answered

Deleting selected notes from stories

  • November 15, 2023
  • 9 replies
  • 869 views

I have been deleting all notes from stories by using notes.everyItem().remove and also with tables, but I was wondering if it was possible to only delete certain notes say for example notes that have some sort of prefix that lets the script know that only these notes should be removed?

Thanks for your help

Alex

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer GNDGN

You're absolutely right.

We can fix this easily by adding

j--;

inside the if-statement.

 

The fixed code is:

var st = app.activeDocument.stories;
var c = 0;
var cSt = st.everyItem().notes.length;

for(i=0; i<st.length; i++) {
    for(j=0; j<st[i].notes.length; j++) {
        if(st[i].notes[j].texts[0].contents.indexOf("Info:") == 0) {
            st[i].notes[j].remove();
            c++;
            j--;
        }
    }
}

alert(c + "/" + cSt + " notes removed.");

 

9 replies

GNDGN
Inspiring
November 15, 2023

This does the job:

var st = app.activeDocument.stories;
var c = 0;
var cSt = st.everyItem().notes.length;

for(i=0; i<st.length; i++) {
    for(j=0; j<st[i].notes.length; j++) {
        if(st[i].notes[j].texts[0].contents.indexOf("Info:") == 0) {
            st[i].notes[j].remove();
            c++;
        }
    }
}

alert(c + "/" + cSt + " notes removed.");

 

In this example, the note is only being removed if it starts with Info:.

____________________Robotic Process Automation in Desktop Publishing (Book): https://doi.org/10.1007/978-3-658-39375-5
Inspiring
November 15, 2023

That is perfect! Thank you very much for your help

Brito Haroldo
Inspiring
November 15, 2023

Hello @Alex25077296wbvx ,

 

If you are already using a script for this, it seems to me that a supplement using "if" is enough to resolve the issue only in those that meet the condition defined in the "if".

 

It's worth noting that you can "look" and apply the "if" condition to what you want to delete or what you don't want to delete. It's just a choice of how to construct the condition, perhaps determined by how your content looks.