I'm trying to turn off ligatures and hyphenations in all style sheets. The script works, but I get an alert that I have to click through.
The specific line causing the issue seems to be
!ev.isValid && app.eventListeners.add("afterOpen",myfunc).name = "onAfterOpen";
Currently, I just click no to the dialog and don't show this again, but it would be nice to remove the problem if possible. Can anyone help?
main();
function main() {
var ev = app.eventListeners.itemByName ( "onAfterOpen" );
!ev.isValid && app.eventListeners.add("afterOpen",myfunc).name = "onAfterOpen";
}
function myfunc (myEvent){
var doc = app.activeDocument;
var allCharacterStyles = doc.allCharacterStyles;
var allParagraphStyles = doc.allParagraphStyles;
//alert ("Cleaning Character Styles.");
for (i = 1; i < allCharacterStyles.length; i++) {
allCharacterStyles[i].ligatures = false;
}
//alert ("Cleaning Paragraph Styles.");
for (i = 1; i < allParagraphStyles.length; i++) {
allParagraphStyles[i].ligatures = false;
allParagraphStyles[i].hyphenation = false;
}
//alert ("All Done.");
}
I've isolated the issue to one line:
!ev.isValid && app.eventListeners.add("afterOpen",myfunc).name = "onAfterOpen";
The error suggests a window is open, but I am not triggering a window.

Try this variant of the code:
Alternatively you can replace the lines:
with:
or:
It will run the function before the main window is show.
The handler 'afterOpen' runs twice. First its event is 'Document' (in this case there is no
app.activeDocumentyet, you have to usevar doc = event.parentto address the opened document), the second event is 'LayoutWindow'.