Copy link to clipboard
Copied
Hi,
My goal : when the operator save his current document, I display my own screen (build in jsx) in which one of the options is 'close document'.
In the validate process, I detect the close option and call the jsx procedure document.close (), but this produce an error : impossible to close the document because I'm inside the event procedure. How can I solve this problem ?
BR,
Dominique
EDIT [moved by moderator to In Design Scripting]
Copy link to clipboard
Copied
Are you using beforeSave of AfterSave ? If the former, you may prefer the latter.
Copy link to clipboard
Copied
I use the afterSave event.
This what I did :
MyFunction ()
{
...
dom.addEventListener("afterSave", SaveBdx);
...
}
function SaveBdx (docEvent)
{
...
if (reply == 1)
dom.close ();
...
}
When executing dom.close (), I have the error : Close document impossible, because this is the target of an active event. 😞
Copy link to clipboard
Copied
if (reply!==1){ docEvent.preventDefault()}
Copy link to clipboard
Copied
It doesn't work. I have got another error : 'impossible to cancel this event'.
May be I have to found a way to post a close event if the condition is valid.
Copy link to clipboard
Copied
docEvent.stopPropagation();
docEvent.preventDefault();
Copy link to clipboard
Copied
#targetengine 'onAfterSave'
var main = function() {
var ev = app.eventListeners.itemByName ("onAfterSave");
!ev.isValid && app.eventListeners.add ('afterSave', onAfterSave).name = "onAfterSave";
function onAfterSave (evt) {
var myIdleTask = app.idleTasks.item("afterSaveIdle");
if ( !myIdleTask.isValid ) {
app.idleTasks.add({name:"afterSaveIdle", sleep:100});
}
var onIdleEventListener = myIdleTask.addEventListener(IdleEvent.ON_IDLE, onIdleEventHandler, false);
function onIdleEventHandler(myIdleEvent){
myIdleEvent.parent.sleep = 0;
var c = confirm ("Shall we close the doc ?", true, "What's next ?");
c && evt.parent.close();
}
}
}
main();
Just wait for indesign to be idle
Loic
Copy link to clipboard
Copied
Thanks Loic.
It work fine with some adjustments.
BR,
Dominique