Empty output when using some shell commands via AppleScript's "do shell script" AppleScript allows you to run shell commands with do shell script. It's easy to assign a variable to an output of such command.
set theResult to do shell script &quot;echo everything&quot;

&gt;&gt; theResult = &quot;everything&quot;

On macOS you also can run Javascript code in Terminal with osascript:
osascript -l JavaScript &lt;&lt; EOF

console.log('everything');

EOF

&gt;&gt; everything

However, if you execute this piece from AppleScript, you get nothing:
set theResult to do shell script &quot;osascript -l JavaScript &lt;&lt; EOF

console.log('everything');

EOF&quot;

&gt;&gt; theResult = &quot;&quot;

I also tried to assign a shell variable to the osascript output and to print it with echo. Again, works in Terminal:
theString=$(osascript -l JavaScript &lt;&lt; EOF

console.log('everything');

EOF
)

echo $theString&quot;

&gt;&gt; everything

But it still does not work when executed via do shell script:
set theResult to do shell script &quot;theString=$(osascript -l JavaScript &lt;&lt; EOF

console.log('everything');

EOF
)

echo $theString&quot;

&gt;&gt; theResult = &quot;&quot;

Why is this happening? How to make it work?
I'll appretiate your help.
My goal is to be able to do some text processing with Javascript within an AppleScript script.
I'm not interested in putting Javascript code into external .js file, I prefer to keep it in place.
console.log within osascript outputs to stderr (standard error), not stdout (standard out). Redirect stderr to stdout for the output to be captured to a variable using 2&gt;&amp;1.
set theResult to do shell script "osascript -l JavaScript 2>&1 &lt;&lt; EOF
console.log('everything');
EOF"