I am new to Cocoa and AppleScript. Recently I want to do something via the "do shell script" command in Cocoa-AppleScript many times, and show a window with a progress bar at the same time to indicate how many times I've done.
My code looks like this:
property progressBar: missing value
on applicationWillFinishLaunching_(aNotification)
repeat with i from 1 to 8
set progressBar's doublevalue to i
do shell script "sleep 1"
delay 1
end repeat
end applicationWillFinishLaunching_
This will show up a progress bar and indicates the progress. However, the window that contains the progress bar will be inactive until the repetition is finished. I think this is because the Cocoa-AppleScript app have only one thread so when it's doing the "do shell script" command the GUI just cannot handle other events. I tried to let the shellscript run in background with a tailed "&", but it behaves like hanged and still consumes a lot of time.
I think even the "do shell script" command can be done in the background I still need to be notified when it's finished to update the progress bar, but I don't know how to achieve that.
So my question is: How to do something via "do shell script" asynchronously, and be informed when the job is finished, in Cocoa-AppleScript?
(By the way, if I remove that "delay 1" line, the progress bar will not even update, does anyone know the reason?)