Skip to main content
Inspiring
October 17, 2016
Answered

Alerts for multiple Documents

  • October 17, 2016
  • 2 replies
  • 504 views

Hi what i'm trying to do is Display the amount of corrections that were made in an alert.  i have it set and working for one document.  but when i change text on multiple documents it will not display the Amount Corrected.  It will correct them but just not display a number. The part i'm having trouble with is Line 9.  As indicated.  If its off The Amount Of corrections in my alert will display correctly(Only for the active Document).  If its On the corrections will Be done to all Documents (If my All Documents Check box is active.) but will not display a total amount of corrections for all documents.  In a nut shell i'm wanting this to perform like the Find/Replace built into indesign.  Display All Corrections made.  If i have 10 documents with 1 correction each.  I want it to display 10 if i only want to check one document i want it to display 1.  Can someone help me with this?

function DBLS(target, findProps, changeProps){    

var changes, numCHGS, alerts, alerts1, alert2;

  app.findChangeTextOptions.caseSensitive = true;    

  app.findGrepPreferences = app.changeGrepPreferences = null;    

  app.findGrepPreferences.properties = findProps;    

  app.changeGrepPreferences.properties = changeProps;

    //    target.changeGrep(); // This is what makes the correction work on all open Documents. If this is turned on it will not allow me to display the amount of corrections.   It just shows up as 0 If this is off like now it will display The amount of Correction (Only on active Page)

        changes = app.documents[0].changeGrep();

        numCHGS = changes.length;

        alerts = [numCHGS+"   Double Space", SP+"   Space Period", SC+"   Space Colon", DR+"   Double Return"];

        alerts1 = [ENG+"   Important Statement and MSDS"];

        alerts2 = [CCH+"    Pink ? to A Contains", CE+"    Pink ? to E Contains", CK+"    Pink ? to K Contains", spCOM+"    Space Comma"];

alert("Corrections Made:\r"+alerts.join("\r")+"\r-----------------------------------\rImportant and SDS:\r-----------------------------------\r"+alerts1.join("\r")+"\r-----------------------------------\rCONTAINS:\r-----------------------------------\r"+alerts2.join("\r"));

}

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

Because you got there, you may want to output the result to a log file. Alerts can be a pain with long strings.

var result = "Corrections made…";

var log = new File(Folder.desktop+"/log.txt");

log.encoding = "UTF-8";

log.open('w');

log.write(result);

log.close();

log.execute();

FWIW

Loic

2 replies

Loic.Aigon
Loic.AigonCorrect answer
Legend
October 18, 2016

Because you got there, you may want to output the result to a log file. Alerts can be a pain with long strings.

var result = "Corrections made…";

var log = new File(Folder.desktop+"/log.txt");

log.encoding = "UTF-8";

log.open('w');

log.write(result);

log.close();

log.execute();

FWIW

Loic

cbishop01Author
Inspiring
October 18, 2016

I have this where it displays the information but it still shows the Number of open Documents (4) as opposed to the Total number of corrections.  I dont mind using a log file it works just as well as the Alert. And i could actually display more information. I'm just still having trouble with displaying the Correct info.

Loic.Aigon
Legend
October 18, 2016

if you call find/change operations on the app object it will process every single open document.

tpk1982
Legend
October 18, 2016

change line 9 with this..

changes = app.documents.everyItem().changeGrep(); 

documents[0] means the active document

HTH

K

Loic.Aigon
Legend
October 18, 2016

tpk1982

There is a fundamental difference between activeDocument property and documents[0]. activeDocument does access the item zero of the app's documents collection. So the lack of open documents will throw an error immediately.

Using documents[0] doesn't necessarly throw error as long as you don't try to reach any property of methods. So you can have a script """"working""""" with documents[0] even if there isn't any document open.

So in both case, it's worth preventing hiccups by either check:

app.properties.activeDocument //will return undefined but no error thrown when app.activeDocument can.

OR

documents[0].isValid as isValid will check the reference status and return either true/false.

FWIW

Loic

tpk1982
Legend
October 18, 2016

Thanks Loic for your detailed explanation