Faster repeated calls to osascript

i=1 while [ $i -le 100 ] do # ruby -e '"x"' # ~1s # perl -e '"x"' # ~1s # python -c '"x"' # ~3s osascript -e '"x"' # ~13s i=$(( $i + 1 )) done
Is there any way to make calls (or repeated calls) to osascript faster?

It’s a high level language, it’s never been fast, just immensely useful.

Try putting your osascript commands into a separate file. Eg:
#!/usr/bin/osascript
repeat 100 times
“x”
end

Of course you could just do the repeating inside a single call:

osascript -e 'repeat 10000000 times' -e '"x"' -e 'end repeat' # ~3 s

Running as an external .scpt, .applescript or shell script with osascript as the interpreter is just as slow.

Right, you can’t reduce the overhead of calling osascript so the only way to make your script go faster is to reduce the number of times you call it. Like, if you’re calling it within a loop, try making the whole loop part of the osascript instead. Or maybe try writing your script as an osascript, calling bash only when necessary - the overhead of a “do shell script” is much less than that of calling osascript.