Error handling InDesign CS5脚本:打开文档没有响应,并且不是';你不会犯错误吗?

Error handling InDesign CS5脚本:打开文档没有响应,并且不是';你不会犯错误吗?,error-handling,execute,adobe-indesign,extendscript,Error Handling,Execute,Adobe Indesign,Extendscript,我使用方法myFile.execute()以编程方式打开InDesign文档(在本例中,它是一个应用了样式的空白文档)。 文档有时会被打开,有时则是而不是。。。似乎脚本在完成之前没有足够的时间打开文件。 这是因为在使用alert(template.name)进行测试时,它确实显示了我正在查找的文件名,并且脚本在应用file(template.execute()(变量template本身已经是一个file对象,但只是template.execute()也不工作)。 以下是相关代码: 那么



我使用方法
myFile.execute()
以编程方式打开InDesign文档(在本例中,它是一个应用了样式的空白文档)。

文档有时会被打开,有时则是而不是。。。似乎脚本在完成之前没有足够的时间打开文件。


这是因为在使用
alert(template.name)
进行测试时,它确实显示了我正在查找的文件名,并且脚本在应用
file(template.execute()
(变量
template
本身已经是一个
file
对象,但只是
template.execute()
也不工作)。


以下是相关代码:



那么,脚本可能没有足够的时间加载文档吗?如果是这样,我应该在调用此函数之前创建一个计时器吗?还是有更好的方法以编程方式打开InDesign文档?

打开InDesign文档与文件无关。execute()只需从操作系统的角度打开文件,而无需参考文件本身。您可以通过调用
app.open(file)打开文件

啊,好的,所以没有错误,我只是使用了错误的方法!感谢您澄清这些方法之间的差异。
function openStylesTemplate()
{
    var templateFolder = getScriptFolder(); // with the function below
    var fileArray = templateFolder.getFiles("*.indd"); // an array of all InDesign documents in this script's same folder

    try
    {
        var template = fileArray[0]; // the ONLY InDesign document in the folder
        File(template).execute(); // open the InDesign template document
    }
    catch(e)
    {
        alert("Error: " + e.message + "\n\n" +
                 "Make sure the InDesign styles document is in the same folder as this script,\n" +
                  "and that it is the ONLY InDesign document in this folder, and try again.\n\n" +
                 "This script is in this folder: " + templateFolder + ".");

        exit();
     }
} // end of function openStylesTemplate