Olav,
I have downloaded and looked through the documentation and examples at the link kindly posted. Thank you. As expected, it did not help me, which is no fault of yours!
I have managed to get this far, by hacking a script that I finally found at the Adobe forums that works with “afterOpen”.
The problems I have so far and minor, but annoying (Mac OS and CS6):
1) When InDesign is run each time, I receive a warning dialog box stating that the startup script generated the following error “no document is open”. I understand why this is happening, however it is less than ideal. I am offered a choice of disabling the event handler, yes or no. No is the obvious choice. I can of course tick the “don’t show again” option, however I am hoping that there may be another event that I could use or a work around to remove this error without having to use the “don’t show again” to hide the error.
2) There is a 6 second or so delay while ExtendScript Toolkit is launched, before the script runs. A dialog appears “You are about to run a script in Adobe InDesign CS6. You should only run scripts from a trusted source. Do you want to run the script? Yes or No?”
I don’t have to answer this ExtendScript Toolkit message, the script runs on the open document fine in InDesign – the delay is not good though. I don’t know why this has to happen in the first place. This is painful and may cause impatient users to think that the program has locked up. When the script is run from the Scripts Panel it runs instantly. So the 6 second delay is either due to the startup script/event implementation or ExtendScript Toolkit kicking in. Why is and is there a way to stop ExtendScript Toolkit from being launched? I have looked in Preferences, however nothing leaps out at me. A google search did not help either…
Script snippet below:
#target indesign // It appears that this line is optional? I have tried removing it and there is no difference in execution
#targetengine "session"
var myEventListener = app.eventListeners.add("afterOpen", myDocOpen, false);
function myDocOpen(myEvent)
{
var myDoc = app.documents[0];
// Insert the script code that would usually be run manually from the GUI here…
Thanks again for your time and patience Ole!
Stephen Marsh