【问题标题】:How to call a python or shell script from within Extendscript?如何从 Extendscript 中调用 python 或 shell 脚本?
【发布时间】:2013-01-04 00:23:19
【问题描述】:

我有一个需要从 Extendscript 脚本中调用的 python 脚本。是否有任何可用的库函数可以做到这一点?我尝试在文档和许多其他在线资源中找到解决方案,但到目前为止对我没有任何帮助。任何帮助表示赞赏。

【问题讨论】:

    标签: adobe photoshop adobe-illustrator extendscript adobe-premiere


    【解决方案1】:

    ExtendScript File 对象有一个 execute() 方法,如 F* 所示。 我不知道 .term 文件,而是使用 .command 文件,这是一个普通的 shell 脚本而不是 XML。

    如果在 InDesign 中运行,您可以绕过 Terminal.app 并使用 AppleScript:

    myScript = 'do shell script "diff f1 f2 > o" ';
    app.doScript(myScript, ScriptLanguage.applescriptLanguage);
    

    【讨论】:

    • 是的,.command 文件比冗长的 .term 文件更酷! (不认识他们)唯一的事情是你必须让它可执行。 .term 文件立即执行
    【解决方案2】:

    看看this example
    它在脚本文件旁边创建一个.term 文件并执行它。

    这是一个干净的版本:

    main();
    function main() {
      var script_file = File($.fileName); // get the full path of the script
      var script_folder = script_file.path; // get the path from that
      var new_termfile = createTermFile("execute_something", script_folder);
      new_termfile.execute(); // now execute the termfile
    }
    /**
     * creates a .term file
     * @param  {String} term_file_name --> the name for the .term file
     * @param  {Strin} path --> the path to the script file
     * @return {File}                the created termfile
     */
    function createTermFile(term_file_name, path) {
    /*
    http://docstore.mik.ua/orelly/unix3/mac/ch01_03.htm
    1.3.1.1. .term files
    You can launch a customized Terminal window from the command line by saving some prototypical Terminal settings to a .term file,
    then using the open command to launch the .term file (see "open" in Section 1.5.4, later in this chapter).
    You should save the .term file someplace where you can find it later, such as ~/bin or ~/Documents.
    If you save it in ~/Library/Application Support/Terminal, the .term file will show up in Terminal's File  Library menu.
    To create a .term file, open a new Terminal window, and then open the Inspector (File  Show Info, or -I)
    and set the desired attributes, such as window size, fonts, and colors. When the Terminal's attributes
    have been set, save the Terminal session (File Save, or -S) to a .term file (for example, ~/Documents/proto.term).
    Now, any time you want to launch a Terminal window from the command line, you can issue the following command:
     */
      var termfile = new File(path + "/" + term_file_name + ".term");
      termfile.open("w");
      termfile.writeln(
          "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
          "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\"" +
          "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" +
          "<plist version=\"1.0\">\n" +
          "<dict>\n" +
          "<key>WindowSettings</key>\n" +
          "<array>\n" +
          " <dict>\n" +
          "<key>CustomTitle</key>\n" +
          "<string>My first termfile</string>\n" +
          "<key>ExecutionString</key>\n" +
          "<string>python\nprint \"Hello World\"\nexit()</string>\n" +
          "</dict>\n" +
          "</array>\n" +
          "</dict>\n" +
          "</plist>\n");
      termfile.close();
      return termfile;
    };
    

    【讨论】: