【问题标题】:Indesign extended Script unable to create a file in Mac OS 10.16Indesign 扩展脚本无法在 Mac OS 10.16 中创建文件
【发布时间】:2021-11-28 10:44:53
【问题描述】:

我有一个用于 indesign 脚本的 jsx 脚本。下面的函数用于写入文件。它在 Windows 中完美运行。在 mac 中,它无法从应用程序文件夹中创建不读取文件。是不是和mac的权限有关??

我确实尝试过使用 applescript 创建文件。代码工作正常,没有错误,但没有创建文件。与以下功能相同。该代码完美运行。但我无法在文件夹中创建 txt 文件。

fileobject = "应用程序/文件夹名/文件名.txt" 文件内容 = "文本"

function writeToFile(fileObj, fileContent){ 
                 encoding = encoding || "utf-8";    
                 fileObj = (fileObj instanceof File) ? fileObj : new File(fileObj);    
                 var parentFolder = fileObj.parent;   
                    if (!parentFolder.exists && !parentFolder.create())     
                         throw new Error("Cannot create file in path " + fileObj.fsName);  
                         fileObj.encoding = encoding;   
                         fileObj.open("w");   
                         fileObj.write(fileContent);
                         fileObj.close(); 
                         return fileObj;
             }

【问题讨论】:

  • 它在 10.15 上对我有用,所以你应该没有问题。这将写入顶部的应用程序文件夹。您确定您没有检查 /Users/YourName/Applications 中的本地用户 Applications 文件夹,而不是 /Applications 中的顶级 Applications 文件夹吗?

标签: macos scripting jsx adobe-indesign extendscript


【解决方案1】:

我已经在 MacOS 10.13 上尝试过,效果很好:

function writeToFile(fileObj, fileContent) {
  encoding = "utf-8";
  fileObj = (fileObj instanceof File) ? fileObj : new File(fileObj);
  var parentFolder = fileObj.parent;
  if (!parentFolder.exists && !parentFolder.create())
    throw new Error("Cannot create file in path " + fileObj.fsName);
  fileObj.encoding = encoding;
  fileObj.open("w");
  fileObj.write(fileContent);
  fileObj.close();
  return fileObj;
}

writeToFile('/Applications/folder/filename.txt', 'text');

基本上它也应该在 10.16 上工作。如果不是,则可能与安全设置有关。将用户文件保存到系统文件夹/Applications 等不是一个好主意。

您能否尝试将文件保存到用户文件夹:~/Desktop~/Downloads

【讨论】:

  • 搞定了。非常感谢。
猜你喜欢
  • 1970-01-01
  • 2018-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-30
  • 2014-01-28
相关资源
最近更新 更多