修复 InDesign 脚本中的 doScript 函数错误
fix doScript function error in InDesign script
我为 InDesign 编写了一个脚本,并使用 doScript 运行 一个 bat 文件。此脚本适用于某些系统,但不适用于其他系统。
错误在图像中。
我 运行 作为 InDesign 管理员。但它给出了另一个错误。
如何修复错误?
function batFile(str) {
var path = "~\AppData\Roaming\test\";
var filename = 'b1.bat';
var file1 = new File(path + filename);
file1.encoding = 'UTF-8';
file1.open('w');
var txt = "systeminfo | findstr /B /C:\"OS Name\" /C:\"OS Version\">%appdata%\test\t1.txt"
file1.write(txt);
file1.close();
var cmdcode = "CreateObject(\"WScript.Shell\").Run \"%appdata%\test\b1.bat\", 0, True";
app.doScript(cmdcode, ScriptLanguage.visualBasic, undefined, UndoModes.FAST_ENTIRE_SCRIPT);
var result = path + "t1.txt";
var arry = openFile2(result);
if (arry.length != 0) {
return arry;
} else {
return "null";
}
}
**
更新
我找到问题了。
当一个用户名由两部分组成时,比如“你的名字”就会出现这个问题。为了解决这个问题,我们需要把地址放在两个双引号里。
var txt = "systeminfo | findstr /B /C:\"OS Name\" /C:\"OS Version\">\"%appdata%\test\t1.txt"\"
**
更新 2
在Windows中,当用户使用OneDrive时,AppData路径也会发生变化,导致doScript无法运行。例如:
c:\用户\用户名\应用数据
更改为:
c:\用户\用户名\onedrive\appdata
我不知道你的脚本有什么问题。但为了以防万一,您可以 运行 bat file 这样:
var bat_file = File("your_file.bat");
bat_file.execute();
更新
根据您的代码,我可以提供解决方法:在您的 bat 文件中添加 & echo ok > %appdata%\test\ok.txt
并在继续之前检查文件 ok.txt
是否存在。
function batFile(str) {
var path = "~\AppData\Roaming\test\";
var filename = 'b1.bat';
var file1 = new File(path + filename);
file1.encoding = 'UTF-8';
file1.open('w');
var txt = "systeminfo | findstr /B /C:\"OS Name\" /C:\"OS Version\">%appdata%\test\t1.txt";
// add the file 'ok.txt' after the previous command is finished
txt += " & echo ok > %appdata%\test\ok.txt";
file1.write(txt);
file1.close();
// run the bat file
file1.execute();
// check if the file 'ok.txt' exists before going further
var ok = File(path + "ok.txt");
while (!ok.exists) $.sleep(100);
ok.remove();
// do stuff
var result = path + "t1.txt";
var arry = openFile2(result);
if (arry.length != 0) {
return arry;
} else {
return "null";
}
}
这是 UserVoice 中报告的已知错误:https://indesign.uservoice.com/forums/601180-adobe-indesign-bugs/suggestions/41072476-type-library-is-not-automatically-created-by-cc202。解决此问题的一个常见技巧是,运行 在客户端机器上至少 以管理员身份 InDesign 一次。这将激活 VBS 支持。
我为 InDesign 编写了一个脚本,并使用 doScript 运行 一个 bat 文件。此脚本适用于某些系统,但不适用于其他系统。 错误在图像中。
我 运行 作为 InDesign 管理员。但它给出了另一个错误。
如何修复错误?
function batFile(str) {
var path = "~\AppData\Roaming\test\";
var filename = 'b1.bat';
var file1 = new File(path + filename);
file1.encoding = 'UTF-8';
file1.open('w');
var txt = "systeminfo | findstr /B /C:\"OS Name\" /C:\"OS Version\">%appdata%\test\t1.txt"
file1.write(txt);
file1.close();
var cmdcode = "CreateObject(\"WScript.Shell\").Run \"%appdata%\test\b1.bat\", 0, True";
app.doScript(cmdcode, ScriptLanguage.visualBasic, undefined, UndoModes.FAST_ENTIRE_SCRIPT);
var result = path + "t1.txt";
var arry = openFile2(result);
if (arry.length != 0) {
return arry;
} else {
return "null";
}
}
**
更新
我找到问题了。 当一个用户名由两部分组成时,比如“你的名字”就会出现这个问题。为了解决这个问题,我们需要把地址放在两个双引号里。
var txt = "systeminfo | findstr /B /C:\"OS Name\" /C:\"OS Version\">\"%appdata%\test\t1.txt"\"
** 更新 2
在Windows中,当用户使用OneDrive时,AppData路径也会发生变化,导致doScript无法运行。例如:
c:\用户\用户名\应用数据
更改为:
c:\用户\用户名\onedrive\appdata
我不知道你的脚本有什么问题。但为了以防万一,您可以 运行 bat file 这样:
var bat_file = File("your_file.bat");
bat_file.execute();
更新
根据您的代码,我可以提供解决方法:在您的 bat 文件中添加 & echo ok > %appdata%\test\ok.txt
并在继续之前检查文件 ok.txt
是否存在。
function batFile(str) {
var path = "~\AppData\Roaming\test\";
var filename = 'b1.bat';
var file1 = new File(path + filename);
file1.encoding = 'UTF-8';
file1.open('w');
var txt = "systeminfo | findstr /B /C:\"OS Name\" /C:\"OS Version\">%appdata%\test\t1.txt";
// add the file 'ok.txt' after the previous command is finished
txt += " & echo ok > %appdata%\test\ok.txt";
file1.write(txt);
file1.close();
// run the bat file
file1.execute();
// check if the file 'ok.txt' exists before going further
var ok = File(path + "ok.txt");
while (!ok.exists) $.sleep(100);
ok.remove();
// do stuff
var result = path + "t1.txt";
var arry = openFile2(result);
if (arry.length != 0) {
return arry;
} else {
return "null";
}
}
这是 UserVoice 中报告的已知错误:https://indesign.uservoice.com/forums/601180-adobe-indesign-bugs/suggestions/41072476-type-library-is-not-automatically-created-by-cc202。解决此问题的一个常见技巧是,运行 在客户端机器上至少 以管理员身份 InDesign 一次。这将激活 VBS 支持。