2012-07-12 74 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