Possible to execute inline JavaScript statement in

2019-06-09 07:04发布

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...

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

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

1条回答
Root(大扎)
2楼-- · 2019-06-09 07:16

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.

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()
查看更多
登录 后发表回答