【问题标题】:Create shell script from Extendscript Toolkit从 Extendscript Toolkit 创建 shell 脚本
【发布时间】:2023-03-27 12:00:01
【问题描述】:

作为 Extendscript 的输出之一,我想创建一个 shell 脚本,然后用户可以执行该脚本。这是一个非常基本的例子:

function createShellScript()
{
    var contents = "#!/bin/bash\ndate";
    var outputFolder = Folder.selectDialog ("Choose where to save:");
    var shFile = new File(outputFolder.absoluteURI + "/shell.sh");
    shFile.open("W");
    shFile.write(contents);
    shFile.close();
}
createShellScript ();

如果我获取生成的文件 (shell.sh),在其上运行 chmod +x 以使其可执行,然后运行它,没有任何反应。 但是,如果我调整上面的脚本以创建相同的内容但一个文本文件 - 所以它输出 shell.txt 打开文件,将内容复制到代码编辑器中的空白文档中,然后另存为 .sh 文件,然后chmod 运行它,它工作正常。

为什么Extendscript在使用这个方法时没有生成正确的.sh文件?

感谢您的帮助。

S

【问题讨论】:

    标签: bash shell extendscript


    【解决方案1】:

    您需要将换行符设置为 unix 样式。例如,shFile.lineFeed = "Unix";

    function createShellScript()
    {
        var contents = "#!/bin/bash\ndate";
        var outputFolder = Folder.selectDialog ("Choose where to save:");
        var shFile = new File(outputFolder.absoluteURI + "/shell.sh");
        shFile.open("W");
        shFile.lineFeed = "Unix";
        shFile.write(contents);
        shFile.close();
    }
    createShellScript ();
    

    【讨论】:

    • 工作愉快。谢谢!
    • 没问题。很高兴我能帮忙:)
    相关资源