Possible to execute inline JavaScript statement in Applescript?

别来无恙 提交于 2020-01-03 04:38:44

问题


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:


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()


来源:https://stackoverflow.com/questions/35758601/possible-to-execute-inline-javascript-statement-in-applescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!