可以在 Applescript 中执行内联 JavaScript 语句吗? [英] Possible to execute inline JavaScript statement in Applescript?

查看:29
本文介绍了可以在 Applescript 中执行内联 JavaScript 语句吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以告诉Chrome或Safari执行JavaScript(或完全用JS编写... à la JXA)但同时回答另一个问题,我很好奇...

I know that you can tell Chrome or Safari to do JavaScript (or write entirely in JS... à la JXA) but whilst answering another question, I got curious...

有没有办法在 AppleScript 中任意执行内联 JavaScript 语句(无需告诉另一个进程)?

Is there a way to arbitrarily execute an inline JavaScript statement inside an AppleScript (without telling another process)?

到目前为止,我只使用过这样的东西(在 AppleScript 中):

So far I've only used something like this (in an AppleScript):

do shell script "osascript -l JavaScript -e '\"" & myVar & "\".trim()'"

但这似乎是一种愚蠢的解决方法

But that seems such a silly workaround

推荐答案

如果你想编写 JavaScript,那么你应该将脚本编辑器语言设置为JavaScript",并用 JavaScript 编写整个脚本,而不是 AppleScript.

If you want to write JavaScript, then you should set the Script Editor language to "JavaScript", and write the entire script in JavaScript, not AppleScript.

>

如果您不需要访问网页,您可以直接在脚本编辑器中输入您喜欢的任何 JavaScript:

If you don't need access to a web page, you can enter any JavaScript you like directly into the Script Editor:

var myVar = "   whatever   "
myVar = '"' + myVar + '"'
myVar = myVar.trim()

这篇关于可以在 Applescript 中执行内联 JavaScript 语句吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆