Marc’s excellent script doesn’t mark up words. But a script to highlight words in a text isn’t too hard.
First, create a text file that contains all your risk words and save it in the document’s folder under the name risk-words.txt
Then run the below script. It creates a text condition and applies that condition to all the risk words. The advantage of txt conditions is that they don’t show in print (or PDF), or in InDesign’s Preview mode.
(function () {
var condition;
var riskWords;
function getCondition () {
app.documents[0].conditionalTextPreferences.showConditionIndicators =
ConditionIndicatorMode.SHOW_INDICATORS;
var c = app.documents[0].conditions.item('Risk word');
if (!c.isValid) {
c = app.documents[0].conditions.add ({
name: 'Risk word',
indicatorColor: UIColors.YELLOW,
indicatorMethod: ConditionIndicatorMethod.useHighlight
});
}
return c;
}
function highlight (word) {
app.findTextPreferences.findWhat = word;
var w = app.documents[0].findText();
for (var i = w.length-1; i >= 0; i--) {
w[i].applyConditions (condition);
}
}
function getWords () {
var f = File (app.documents[0].filePath + '/risk-words.txt');
if (f.exists) {
f.encoding = ('utf-8');
f.open('r');
var w = f.read().split(/[\r]/);
f.close();
return w;
}
return null;
}
app.findTextPreferences = app.findChangeTextOptions = null;
app.findTextPreferences.properties = {
caseSensitive: false,
wholeWord: true,
includeLockedStoriesForFind: false,
}
condition = getCondition();
riskWords = getWords();
if (!riskWords) {
alert ('Risk words not found');
exit();
}
for (var i = riskWords.length-1; i >= 0; i--) {
highlight (riskWords[i]);
}
}());