このメソッド myFile.execute()
を使用して、InDesign ドキュメントをプログラムで開いています (この場合、スタイルが適用された空のドキュメントです)。
ドキュメントが開かれることもあれば、開かれないこともあります...スクリプトが完了する前にファイルを開く時間がないようです。
これは、テスト時に 探しているファイル名が表示され、適用時にスクリプトが
alert(template.name)
エラーをスロー しないFile(template).execute()
ために発生しました (変数 template
自体は既に File
オブジェクトですが、単に template.execute()
動作していません)。
関連するコードは次のとおりです。
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
では、スクリプトがドキュメントをロードするのに十分な時間がないのではないでしょうか? もしそうなら、この関数が呼び出される前にタイマーを作成する必要がありますか? または、InDesign ドキュメントをプログラムで開くためのより良い方法はありますか?