0

The window is opening fine, but the script will not continue until the popup window is manually closed! This is not desirable, as I would rather the window close itself after  n  seconds...

So do I have to open the window in a separate thread from the rest of the script? Is that even possible?

Here's my code so far:

function showMessageWindow()
{
    var script = getScriptName(); // initialized from the function below
    var message = new Window("dialog", script);
    message.add("StaticText", undefined, "The script " + script + " is now running, please wait...");

    message.show();

    var startTime = new Date().getTime(); // in milliseconds
    var currentTime = new Date().getTime(); // in milliseconds
    var waitTime = 5000; // 1000 milliseconds is 1 second

    var delay = function()
    {
        while( (currentTime - startTime) < waitTime)
        {
            currentTime = new Date().getTime(); // in milliseconds
        }
    } // end of closure delay

    delay(); // calling the delay closure function here
    message.close(); // close the message after the specified delay time

} // end of function showMessageWindow

    // called from the function showMessageWindow
    function getScriptName()
    {
        var scriptName = "";

        try
        {
            scriptName = File(app.activeScript).name;
        }
        catch(e)
        {
            scriptName = File(e.fileName).name;
        }

        return scriptName;
    } // end of function getScriptName
RobC
  • 22,977
  • 20
  • 73
  • 80
Ian Campbell
  • 2,678
  • 10
  • 56
  • 104

1 Answers1

1

dialog type windows are modal dialogs preventing any background operations. However even with a non modal window, I am not sure you can get parallel execution of both routines from teh same script. I am pretty sure teh script engine will kindly wait for yt-our delaying routine to end before keeping on moving :\

The only way I could deal with such asynchronous processus was using scriptUI in combination of a swf file and have any timer stuff done in AS3. That way you can have script execution to move on within InDesign and have your loop running in the swf file. I did that once especially to monitor a hot folder.

BTW : you have a mistake in your code => message.add("StaticText", undefined,… That should be statictext in lowercase ;)

Loic
  • 2,173
  • 10
  • 13
  • Thanks @Loic! Hmm, ActionScript... Would this also be possible with VBA or AppleScript, or was ActionScript particularly useful? This is very interesting, though I have opted to use a confirm box that calls `exit()` if `No` is clicked (*not* asynchronous, but user-friendly for my purposes afterall). Ah, and `statictext` in *lowercase*, thanks for pointing that out. – Ian Campbell Jul 18 '12 at 05:17
  • Not sure Applescript can help neither. I don't know what VB has to offer. – Loic Jul 18 '12 at 22:13
  • applescript, vb and javascript have the same functionality – Frederik Witte Nov 14 '14 at 14:39