Can I make an Applescript output to stdout while it runs?

Conceptually, what I’d like to do is something like this:

repeat with x from 1 to 10
   write to stdout x
   -- do something time consuming
end repeat

And then, when I execute the above script via osascript in a Terminal window, see…

1
(pause)
2
(pause)
3

…etc., come through to the Terminal window. “log” doesn’t work. (In fact, when using osascript, as far as I can tell “log” sends information straight to the bit bucket – not to the Terminal app, not to the Console app either.)

The only stdout output I seem to be able to get from an Applescript is the final “result” value from the script. I’d really like to get feedback via stdout from a script the whole time the script is running, not only one final value when it terminates.

Is this possible? If so, how?

What I’m trying to do is this: I want to have a cross-platform Java app – not a Cocoa Java app – run an Applescript which controls iTunes, and get feedback on the progress of that script.

In its current version, when this app runs on Windows, it uses Runtime.exec to execute a JavaScript, and the script talks to iTunes via the iTunes COM SDK. So that the Java app can report on progress of the script, the script uses WScript.Echo to send progress info out to stdout, which the Java app can see and report as the script goes along.

I’d like to be able to use Runtime.exec on the Mac to perform the shell command “osascript myItunesScript” and similarly see progress as the script executes via stdout (or stderr would do). As it looks right now, about the only feedback I get via stdout is the last result value when the script is completely finished executing.

If I can’t get anything else reported to stdout, I’ll have to resort to something ugly (as if Runtime.exec isn’t ugly enough already!) like writing progress status to a temp file which the Java app reads to see what’s going on.

Of course, if anyone knows how to get a (mostly) pure Java app to more directly do Applescripting or AppleEvents, that’d be even better.

(It’s too bad JavaScript OSA isn’t both more up-to-date and a standard part of OS X.)