Question

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
Was it helpful?

Solution

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 ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top