Hi,
In a selected Illustrator area text object, I'd like to put all allergens of an ingredient list in a bold font.
Example ingredients list:
Ingredients: sausage 34% (pork 67%, water, potato starch, pork bacon, salt, soy protein, spices (contains mustard), herbs (contains celery), milk protein, emulsifier (triphosphates), antioxidants (sodium ascorbate, monosodium glutamate), preservative (sodium nitrite)).
My allergens array:
allergenList = ["soy", "mustard", "celery", "milk"]
(part of) my script:
var ingredientList = doc.selection[0].textRange;
var i = 0;
for (i=0; i < ingredientList.words.length; i++){
var wordSelected = ingredientList.words[i];
//checking matches between ingredientList and allergenList
var k = 0;
for (k=0; k < allergenList.length; k++){
if (wordSelected.contents == allergenList[k]){
// formatting the selection
wordSelected.characterAttributes.textFont = textFonts.getByName("MyriadPro-BoldCond")
break;
}
}
}
But it appears the .word subrange is not the ideal approach: when an allergen word is followed by a parenthese, it is not correctly selected. As a matter of fact, the .contents returns a word without the last letter (e.g. 'celer' instead of 'celery')
I am sure there are better and smarter approaches but I am a newby to AI scripting 🙂
Also, I think it would be wiser to load the allegens list from a text file rather than a hard-coded array, but that is another challenge to tackle.
Me and all food sensitive people will be very grateful for your help:)