可能的AppleScript的执行内嵌的JavaScript语句? [英] Possible to execute inline JavaScript statement in Applescript?

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

问题描述

我知道,你可以告诉 Chrome或Safari浏览器做的JavaScript (或完全用JS写...点菜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语句(不包括告诉 ING另一个进程)?

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天全站免登陆