How to show output as it is generated by Unix command?

I have only started programming both Actionscript and Actionscript Studio today so my questions are very newb orientated. Hopefully someone here with significantly more skill than me can point me in the right direction with my problem:

I am trying to make a nice simple interface to a Unix command called Unison which is able to syncronise two or more folders on local or remote servers. Everything is working fine on the command line and I am just struggling with getting my Applescript Studio interface to ‘live update’ as the Unix command is executing. I have a button, a progress bar and a scrolling textfield in my interface. All of them work, but only seem to update once the command has finished executing. How do I get it to flow in a more logical manner? I want to user to click the button, have the progress bar start to twirl to indicate some kind of progress and have the output generated by the Unix command printed to the textfield as it happens.

Here is my Applescript so far:

on clicked theObject
	tell progress indicator "progressbar" of window "main" to start
	with timeout of 1000000 seconds
		
		try
			
			set theResult to do shell script "sudo /opt/local/bin/unison -batch mybackup 2>&1" as string with administrator privileges
		on error errormsg
			
			set theResult to errormsg
			
		end try
		
		set the contents of text view "output" of scroll view "output" of window "main" to theResult
		set needs display of text view "output" of scroll view "output" of window "main" to true
		
	end timeout
	tell progress indicator "progressbar" of window "main" to stop
	
end clicked

on should quit after last window closed theObject
	return true
end should quit after last window closed

Most of this code is pulled from various tutorials and examples, so there are probably neater ways of doing this. Any advice is greatly appreciated, or if you need any more info let me know.

My problem is very similar. (I’m also a newbie with AS Studio.)

I’d like to a run a shell script that generates output, normally, at the command line while the command is running. I’d like this output to display in an text field while the output is being generated. At present, I’m able to capture the output into a variable and then display it, but the display occurs after the command has completed running. I’d like the output to display in real-time to provide a visual cue as to the progress of the script. In addition, I’d like the shell script to run with admin privileges.

Here’s a sample snippet illustrating where I’m at so far.


set content of text field 1 of window 1 to do shell script 'rsnapshot '" & _myArgs

Any pointers?

  • Orest

Model: MacBook
AppleScript: 1.10.7
Browser: Firefox 2.0.0.7
Operating System: Mac OS X (10.4)

Any feedback on this? Is it just not do-able?