4

I have a question concerning Indesign script.

Why does it work, when you close a window like:

submitButton.onClick = function(){
    close();
}

But when I try to execute a function afterwards like:

submitButton.onClick = function(){
    close();
    tagElements();
}

(note I am using the "with" tag, so no window.close() is needed)

The window does not close? Am I forgetting about something here? Shouldn't the window close, and then execute the function?

The window is initialized like:

var de = new Window('dialog', 'Descriptions');
Frederik Witte
  • 1,167
  • 2
  • 11
  • 35
  • It should work. Could you also link include the code for the function `tagElements();`? Does the function `tagElements();` work if you only execute that function on the button click? – user25312 Nov 17 '14 at 14:52
  • 1
    It does not, because functions can not be executed while a dialog is open in indesign. So the dialog has to be closed first. – Frederik Witte Nov 17 '14 at 14:58
  • The issue does not seem easily replicated, partly due to the scattered snippets of code. For example, there is no `with` in the code shown (you *say* you use it; but maybe you are using it wrong!). Can you add one single [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) that still has the problem? – Jongware Nov 24 '14 at 10:03
  • @Frederik Witte: did you try my answer ? – M. Page Nov 26 '14 at 09:30

4 Answers4

1

Replacing close() with de.close() should do the trick. This works for me;

var de = new Window('dialog', 'Descriptions');
btn = de.add('button', undefined, 'close');  
btn.onClick = function() {  
    de.close();
    alert('foo');
}
de.show();
tkounenis
  • 665
  • 4
  • 18
0

You may have to add a delay after closing (not tried):

function pause(msec) { 
  var done = null; 
  var date = new Date(); 
  var curDate = null; 
  do curDate = new Date(); 
  while(curDate-date < msec); 
  var done = 1; 
  return done; 
} 

submitButton.onClick = function(){
    close();
    pause(500);
    tagElements();
}
M. Page
  • 2,694
  • 2
  • 20
  • 35
0

You need the reference to the Opened window in the code.

submitButton.onClick = function(){
de.close();
tagElements();
}

should work

Dhanilan
  • 183
  • 1
  • 3
  • 15
0

The following has done the trick:

with(de)
    submitButton.onClick = function(){
        close(1);
     }
}
if(de.show){
    tagElements();
}

de.show will be true, when you pass '1' in the close function( 1 == true). On you close button you would just add 'close()' and the if statement will be false.

Frederik Witte
  • 1,167
  • 2
  • 11
  • 35