lescript或bash运行illustratorextend

lescript或bash运行illustratorextend

本文介绍了通过automator applescript或bash运行illustratorextendscript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下命令将运行位于我的桌面上的 SCRIPT_ABC.jsx 。有没有办法采用 SCRIPT_ABC.jsx 的内容并将javascript扩展脚本专门放在automator中,所以当我将其保存为应用程序时,它将包含在程序中?

The following command will run the SCRIPT_ABC.jsx which is located on my desktop. Is there a way to take the contents of the SCRIPT_ABC.jsx and put the javascript extendscript exclusively inside automator so when I save it out as an application it will be included within the program?

 on run {input, parameters}

        tell application "Adobe Illustrator" to open file "Macintosh HD:Users:NAME:Desktop:SCRIPT_ABC.jsx"

        return input
    end run


推荐答案

将整个jsx作为文本体粘贴到applescript中,然后使用 do javascript 命令运行它。 Applescript的一个很大的好处就是能够将参数传递给jsx(用参数{textVariableHere,anotherOneHere} 做javascript myScript)并获得返回的结果!

Paste the entire jsx into your applescript as a text body, then use the do javascript command to run it. Applescript has a great benefit of being able to pass in arguments to the jsx (do javascript myScript with arguments { textVariableHere, anotherOneHere }) and obtain the returned result too!

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应用程序,它非常值得,并且它具有粘贴为字符串文字功能,可以自动转义引号和内容。很有帮助。

So what you see here is an example of a javascript embedded inside the applescript as a string. Lucky for me, I have AppleScript Debugger app which I paid for a long time ago and is well-worth it, and it has the "Paste as string literal" function which auto-escapes the quotes and stuff. Very helpful.

但是您可以看到将变量作为applescript参数传递给javascript的魔力,可以防止很多问题,人们可以在applescript内进行字符串构建以将变量放入其中。

But you can see the magic of passing in a variable to the javascript as applescript arguments which prevents a lot of issues one could have doing string-building inside applescript to put variables in.

尽管您不必使用AppleScript参数将数据放入jsx,但是您可以使用上面提到的字符串构建(我不建议在使用arguments方法时建议这样做),巨大的回报实际上是将返回的jsx数据返回到applescript中。真的很整洁。

Although you don't have to use AppleScript arguments to put data into the jsx, as you can use the string-building mentioned above (which I do not recommend when the arguments way is available for use), the huge payoff is actually getting the returned jsx data back into the applescript. Really neat stuff.

所以您拥有了它,整个辣酱玉米饼馅!我很想知道是否可以使用Windows和VBS + JSX组合进行类似设置的本地方法-如果有人知道这样的事情,请在下面的评论中告诉我。
谢谢!

So there you have it, the whole enchilada! I would be curious to see if there's a comparable native way to do a similar setup with Windows and VBS + JSX combo - if anyone is aware of something like this please let me know in the comments below.Thanks!

PS:
函数中使用的单词 arguments jsx脚本的主要功能的调用实际上是AppleScript使用的关键字,必须像这样拼写出来,否则将无法正常工作。

PS:The word arguments used in the function call of the main function of the jsx script is actually a key-word used by AppleScript and it has to be spelled out like so, otherwise it will not work.

好的,所以也许您不想在自己的网站上粘贴不了任何大型jsx applescript并转义所有引号,等等。

Okay, so maybe you don't wanna paste no huge jsx into your applescript and escape all the quotes, etc.

我明白了。别担心!您可以执行以下操作:

I get it. No worries! You can do the following:

请确保您的jsx与您的应用程序一起安装在某个位置(它可以是二进制的),因此请将以下代表您的jsx正文的代码保存为jsx文件在何处:

Ensure your jsx is somewhere installed along with you app (it could be binary), so save the following code which represents your jsx body as a jsx file wherever:

var docName = app.activeDocument.name;
    alert("Hello from Adobe JSX. Current document name is: '" + docName + "'\n" + args[0]);
    return docName;

在AppleScript中,您只需将jsx部分更改为以下内容:

And in your AppleScript you simply change the jsx portion to the following:

set myJavascript to "
#target illustrator
function test(args){
    #include '/Users/YourName/Wherever/myAppleScriptJsxTest.jsx'
};
test(arguments);
"

BOOM!原理完全一样!那不是吗?

BOOM! Works exactly the same! Isn't that something?

这篇关于通过automator applescript或bash运行illustratorextendscript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 02:09