Sunday, December 4, 2022

#1 2022-11-15 05:24:56 pm

Fredrik71
Member
Registered: 2019-10-23
Posts: 1091

5 times JavaScript in 1 line of code.

Did you know its possible to execute JavaScript 5 different ways in AS in 1 line of code.

JSC is from JavaScriptCore framework I had to made symbol link to /usr/local/bin
(You could find it if you do a search on your machine)

Ps. I didn't include ASObjC with JavaScriptCore framework... its more an 1 line of code.

Node is installed from brew and its version 18.

I try Google-Chrome but couldn't get it to work.

Applescript:

set nodeJavaScript to do shell script "/opt/homebrew/bin/node <<EOF" & linefeed & "console.log(Math.sin(1))"
log nodeJavaScript
set osaJavaScript to do shell script "osascript -l JavaScript -e 'Math.sin(1)'"
log osaJavaScript
tell application "Safari" to set sfJavaScript to do JavaScript "Math.sin(1)" in document 1
log sfJavaScript
set jscScript to do shell script "/usr/local/bin/jsc <<EOF " & linefeed & "Math.sin(1)"
log jscScript
set jsRunScript to run script "Math.sin(1).toString()" in "JavaScript"
log jsRunScript

Last edited by Fredrik71 (2022-11-15 05:28:49 pm)


Node-RED makes it easy to automate IoT

Offline

 

#2 2022-11-15 05:54:00 pm

estockly
Member
Registered: 2009-01-03
Posts: 159

Re: 5 times JavaScript in 1 line of code.

Here's another:

Applescript:

tell application "Google Chrome" to set jsScriptResults to execute (active tab of window 1) javascript "Math.sin(1)"
log jsScriptResults

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)