2012-07-12 75 views
0

窗口正常打开,但脚本将而不是继续,直到弹出窗口手动关闭!这是不可取的,因为我宁愿窗口关闭本身  秒后...

所以我必须从脚本的其余部分一个单独的线程,打开窗口?这甚至有可能吗?

这里是我到目前为止的代码:
InDesign CS5脚本:如何在'n`秒后打开和关闭弹出窗口?

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 

回答

1

对话框中,键入窗口是模态对话框阻止任何后台操作。但是,即使使用非模态窗口,我也不确定是否可以从同一个脚本中并行执行两个例程。我很确定脚本引擎会好心等待yt--我们的延迟例程在继续移动之前结束:\

我可以处理这种异步processus的唯一方法是将scriptUI与swf文件结合使用,并具有任何定时器的东西在AS3中完成。这样,您可以在InDesign中执行脚本执行,并让您的循环在swf文件中运行。我曾经这样做过,特别是要监视一个热文件夹。

BTW:你有一个错误在你的代码=> message.add( “静态文本”,不确定的,... 这应该在小写静态文本;)

+0

感谢@Loic!嗯,动作脚本...这也可以用VBA或AppleScript,或者是ActionScript特别有用吗?这很有趣,尽管我选择使用确认框,如果单击“否”(*不是*异步,但用户友好以用于我的目的),则调用'exit()'。啊,'*小写* statictext',谢谢指出。 – 2012-07-18 05:17:38

+0

不知道Applescript既不能帮助。我不知道VB提供什么。 – Loic 2012-07-18 22:13:12

+0

applescript,vb和javascript具有相同的功能 – 2014-11-14 14:39:47