Repository Public Research preview
1-- Run JavaScript in a tab and print the result.2-- Usage: osascript run-js.applescript <window-id> <tab-index> '<javascript>'3-- The code travels as an argument, so it needs no AppleScript escaping.4-- Return a string (JSON.stringify(...)): objects, undefined and promises come back empty.5on run argv6 set w to (item 1 of argv) as integer7 set t to (item 2 of argv) as integer8 tell application "Safari"9 set r to do JavaScript (item 3 of argv) in tab t of window id w10 end tell11 try12 return r13 on error14 return ""15 end try16end run17