@Mi_D – that is all good and well, but the event will even fire, if you open another LayoutWindow of the same file. Or if you open the StoryWindow of the story editor.
In the context of the original question, this event fires way too much…
Worse, if you open a file:
The event will fire one time even before the to be opened document can be shown in a window. And another time after the document is shown in a window.*
If a new document is created, the event will fire only one time after the new document is shown in a window.*
If you open the Story Editor window, the event fires again one time.
If you open another layout window of a opened document the evnet will fire one time
*these are the only occasions where you possibly want to save the document to a copy in a special folder.
The big question is: how to determine what window belongs to what file, if several files are opened or if new windows of already open files are created.
Code tested on Mac OSX 10.6.8 with InDesign CS5.5, run from ESTK, not running in main().
#target InDesign;
#targetengine "AlertAfterOpenWindow";
var counter = 0;
app.addEventListener("afterOpen", openEvent, false);
function openEvent(){ ++counter; alert("afterOpen-event fired: "+counter); };
To the OP: if you want to test this with the ESTK (ExtendScript Toolkit) and want to get rid of the alert message in InDesign, simply restart InDesign.
Uwe