Skip to main content
manuelb27477138
Inspiring
May 3, 2018
Answered

Counter Find Replace Text with alert

  • May 3, 2018
  • 2 replies
  • 452 views

Hello!

This code replace all text human, and added a Column Break before the human text.

If the text was replace more than want time, I want show an Alert.

My problem with this code is the Column Break is added 2 times, because looks the function is called 2 times and not 1.

Please, how can I do for show the Alert but don't add 2 Column Break each time the script find the text?

app.findTextPreferences = NothingEnum.nothing; 

app.changeTextPreferences = NothingEnum.nothing; 

 

app.findTextPreferences.findWhat = "human\r"; 

app.changeTextPreferences.changeTo = "^M\human\r"; 

 

//this will show changes count

var counter = app.activeDocument.changeText().length;

    if(counter>1){

        alert("BECAREFULL! The text was replace "+ counter + " times");

    }

app.activeDocument.changeText();

Thanks so much in advance.

This topic has been closed for replies.
Correct answer Loic.Aigon

app.findTextPreferences = NothingEnum.nothing;   

app.changeTextPreferences = NothingEnum.nothing;   

   

app.findTextPreferences.findWhat = "human\r";   

app.changeTextPreferences.changeTo = "^M\human\r";   

   

var changed = app.activeDocument.changeText();

var n = changed.length;

if ( n > 1 ) alert("BECAREFULL! The text was replace "+ n + " times");

2 replies

manuelb27477138
Inspiring
May 4, 2018

Hi Loic

thanks so much!

It is fortunate to have people who help like you.

Loic.Aigon
Loic.AigonCorrect answer
Legend
May 4, 2018

app.findTextPreferences = NothingEnum.nothing;   

app.changeTextPreferences = NothingEnum.nothing;   

   

app.findTextPreferences.findWhat = "human\r";   

app.changeTextPreferences.changeTo = "^M\human\r";   

   

var changed = app.activeDocument.changeText();

var n = changed.length;

if ( n > 1 ) alert("BECAREFULL! The text was replace "+ n + " times");