Copy link to clipboard
Copied
Team, so far I've found this to be the best start: Re: Why will this not work on startup?
I've gotten as far as putting a script in the startup scripts folder and it even runs...(I replaced the Then action with a simple alert) But the script given in that discussion's answer seems to do its thing before the document even opens. I'm not sure that's what I want. Here are the basic things I would like my script to do;
Can anybody suggest some tips or a barebones script, ie the beginning and the IF part of the script so that I can fill in the THEN part with the action I want to accomplish?
NOTE: I am a scripting/javascript newbie... please be extra clear with ideas... if you give developer level jargon (without the exact code), I will not understand a thing your saying... Please do not throw this InDesign ExtendScript API (12.0) at me... it looks like a great reference but doesn't translate anything into actual code, therefore it's completely useless to me. (right now)
Thank for any help.
Copy link to clipboard
Copied
Fact is that the kind of code you are looking for and will probably get in a moment from a fellow requires a good understanding of InDesign Object Model. So I guess you won't have much more understanding of the code itself without doing some efforts in getting the meaning of the objects.
Adding a script that would react to file opening is what is called using a startup script. That is to say it will run as long as InDesign is open and to the condition a targetengine has been set. See, another concept to acquire.
Once you get this listener set to the right event (afterOpen) you need a function to catch this event aka an eventListener. Those function use a special argument of "type" Event with specific properties.
Then you have to ensure the object which fired the event is actually the document you are after. Checking one of its property (url, name, whatever) to a reference and then act properly.
Once that done, that could lead to
#targetengine "onAfterOpen"
function main() {
var evName = "onAfterOpen",
ev = app.eventListeners.itemByName ( evName );
!ev.isValid && app.eventListeners.add ( "afterOpen", onAfterOpenHandler ).name = evName;
}
function onAfterOpenHandler ( evt ) {
var doc = evt.parent;
if ( !(doc instanceof Document)
||
doc.name != "toto.indd" ) return;
alert( "That's the kind of document I like to work with !" );
}
main();
HTH
Loic
www.ozalto.com
Copy link to clipboard
Copied
Thanks Loic. I will give this a try. I welcome anything else from anybody else!