javascript - 使用 Applescript 从外部文件调用 Javascript 函数

标签 javascript function applescript photoshop-script

是否可以在applescript中调用javascript文件函数?当 100% 写入 applescript 文件中时,我可以让它工作,或者我可以使用“do javascript file some file”。有没有办法将两者混合起来?像这样的事情:

tell application id "com.adobe.Photoshop"
    tell current document
        do javascript "function(Variable1,Variable1)" in file PathtoJSX
    end tell
end tell

该函数位于外部文件中,但我想从 applescript 传递变量。

更新:

当其他人询问时我发布了它,但 PathtoJSX 是“Javascript 文件 (.jsx) 的路径”,因此 PathtoJSX = 文件“desktop:yourFile.jsx”

最佳答案

我认为您想要做的是将代码的函数部分放在文件中,并通过 AppleScript 将参数作为列表(数组)发送,这很容易做到:

jsx 文件的内容可能是:

testFunc(arguments);

function testFunc(t) {
 alert('argument one: ' + t[0] + '\r' + 'argument two: ' + t[1]);
}

AppleScript 可能是:

tell application id "com.adobe.Photoshop"
  activate
  do javascript PathtoJSX with arguments {"foo", "bar"}
      --I tested using:-- do javascript (choose file) with arguments {"foo", "bar")
end tell

无论您使用什么 JS 代码(文本或文件),您只需确保在该代码中使用 arguments 数组引用即可。 请注意,如果您使用文本变量而不是别名(文件引用)来测试它(就像我所做的那样),则返回字符将需要双重转义。

关于javascript - 使用 Applescript 从外部文件调用 Javascript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23527310/

相关文章:

javascript - 在javascript中扩展函数

Javascript 变量到 Applescript

macos - Automator、AppleScript 还是其他?

javascript - Android 上的 HTML5 视频宽高比不正确

sql - 将函数编辑为 0xdbe

javascript - 创建以特定方式动画的通知弹出窗口?

javascript - 非递归代码递归

shell - 在 Finder 中选择的文件上执行 shell 命令

javascript - MDL 表检索数据检查值

javascript - VB.net 输入键