Polling the output from a long-running shell command

I want to make a little Mac app that replaces some of Disk Utility’s buggy behavior: The Restore operation.

The user would choose a source and a destination volume, and then the app would invoke a command line tool (asr).

Since this tool can run for a long time, up to hours, I need to be able to show its progress.

I can have the tool print lines about its progress. I would need to be able to constantly poll the output of the shell invocation so that I can update my UI accordingly. Is that doable with AppleScript? AFAIK, Applescript only offers an atomic, synchronous, command for shell execution, so that’s not going to work, I guess. And doing it with NSTask seems to be quite complex, using an NSPipe and async handlers - probably not safe to use in AppleScript, either, right? Any ideas?

As long as you’re not pouring out much data, it’s probably do-able without async handlers – you just call availableData on the output file handle repeatedly. This should get you started:

Having said that, I personally wouldn’t. For someone who knows Objective-C, it would probably work out much easier in the end to do it there.