以下命令将运行位于我的桌面上的SCRIPT_ABC.jsx
。有没有一种方法来获取SCRIPT_ABC.jsx
的内容并将javascript扩展脚本专门放入automator中,以便在将其保存为应用程序时将其包含在程序中?
on run {input, parameters}
tell application "Adobe Illustrator" to open file "Macintosh HD:Users:NAME:Desktop:SCRIPT_ABC.jsx"
return input
end run
答案 0 :(得分:1)
将整个jsx作为文本主体粘贴到applescript中,然后使用do javascript
命令运行它。 Applescript的一大优势是能够将参数传递给jsx(do javascript myScript with arguments { textVariableHere, anotherOneHere }
)并获得返回的结果!
set myJavascript to "
#target illustrator
function test(args){
var docName = app.activeDocument.name;
alert(\"Hello from Adobe JSX. Current document name is: '\" + docName + \"'\\n\" + args[0]);
return docName;
};
test(arguments);
"
set myInputVar to "The input string here."
tell application "Adobe Illustrator"
set myResult to do javascript myJavascript with arguments {myInputVar}
end tell
display alert ("Returned Document Name is: '" & myResult & "'")
所以您在这里看到的是一个以字符串形式嵌入在applescript中的javascript的示例。对我来说幸运的是,我有一个很久以前就花钱买的AppleScript Debugger应用程序,它非常值得,并且它具有“粘贴为字符串文字”功能,可以自动转义引号和内容。非常有帮助。
但是您可以看到将变量作为applescript参数传递给javascript的神奇之处,这可以防止很多问题,而这些问题可能需要在applescript中进行字符串构建以将变量放入其中。
尽管您不必使用AppleScript参数将数据放入jsx中,但是您可以使用上面提到的字符串构建(当可使用参数方式时不建议这样做),但巨大的回报是实际上将返回的jsx数据返回到applescript中。真的很整洁。
因此,整个玉米卷饼就在那里!我很想知道是否可以使用Windows和VBS + JSX组合进行类似设置的本地方法-如果有人知道这样的事情,请在下面的评论中告诉我。 谢谢!
PS:
jsx脚本的主函数的函数调用中使用的单词arguments
实际上是AppleScript使用的关键字,必须将其拼写清楚这样,否则它将无法正常工作。
好的,所以也许您不想在自己的applescript中粘贴任何大型jsx并转义所有引号,等等。
我明白了。别担心!您可以执行以下操作:
请确保您的jsx与应用程序一起安装在某个位置(可能是二进制文件),因此无论何时何地,请将代表jsx正文的以下代码保存为jsx文件:
var docName = app.activeDocument.name;
alert("Hello from Adobe JSX. Current document name is: '" + docName + "'\n" + args[0]);
return docName;
在AppleScript中,您只需将jsx部分更改为以下内容:
set myJavascript to "
#target illustrator
function test(args){
#include '/Users/YourName/Wherever/myAppleScriptJsxTest.jsx'
};
test(arguments);
"
BOOM!原理完全一样!那不是吗?
答案 1 :(得分:0)
您可以将.jsx文件复制到Automator应用程序捆绑包的Contents/Resources
文件夹中,并使用 Run AppleScript 操作获取资源
on run {input, parameters}
try
set thePath to path for resource "SCRIPT_ABC" extension "jsx"
tell application "Adobe Illustrator" to open (thePath as POSIX file)
on error errmess
display dialog errmess
end try
return input
end run
注意:重新创建应用程序包时,您将需要将有问题的文件再次复制到包/Contents/Resource
文件夹中,因为每次保存时Automator都会创建一个新的包。
此外,添加文件后,可能需要关闭Automator /脚本编辑器。最后,测试生成的应用程序,看看它是否在请求的应用程序中启动文件。
答案 2 :(得分:0)
这是通过Adobe Illustrator执行〜/ script.jsx(可以有任何jsx脚本)的AppleScript:
tell application "Adobe Illustrator"
do javascript "(function(){//@include '~/script.jsx'}());"
end tell
或者您可以将Adobe Illustrator设置为默认打开所有jsx文件。之后,双击任何jsx文件将使Illustrator执行脚本。它可以在Windows和MacOS上运行。