/* * ExtendScript to set a background color on elements * with @status='changed' or @status='new' in all * files in book * */ Console("Running ExtendScript on book."); // get the active book var book = app.ActiveBook; // get the first component in that book var comp = book.FirstComponentInBook; // iterate over all components while (comp.id) { // get the component name (file name) var compName = comp.Name; // open that file (ok if already open) var doc = SimpleOpen (compName, false); // print a message to the console Console("Processing: "+compName); // call our function to perform the processing fnProcessDoc(doc); // get the next component and loop back comp = comp.NextComponentInBook; } // function that starts the processing of a document function fnProcessDoc(doc) { // get the root element in the file var rootElem = doc.MainFlowInDoc.HighestLevelElement; // run function to process all elements in the file // .. (if it's structured) if (rootElem.id) { fnProcessElements(doc, rootElem); } } // iterative function to walk through all elements function fnProcessElements(doc, elem) { // get the value of the status attribute var statusVal = fnGetAttributeValue(elem, "status"); // check if value is "new" or "changed" if ((statusVal == "new") || (statusVal == "changed")) { // set the background color to "Green" fnSetBackgroundColor(doc, elem, "Green") ; } // scan for more elements var child = elem.FirstChildElement; while (child.id) { fnProcessElements(doc, child); child = child.NextSiblingElement; } } // function to get the specified attribute value function fnGetAttributeValue(elem, attrName) { var attrVal = ""; var attrs = elem.GetAttributes(); for (n=0; n