How to use NSProgressIndicator

Hello All.

I have made a simple ApplescriptObjC app in Xcode to launch shell scripts and then display a dialog. It works fine.

script updater
	property parent : class "NSObject"
	
	on buttonpress_(sender)
		do shell script "say 'good morning everybody'"
		display dialog "Done"
		
	end buttonpress_
		
end script

Since when finished the shell script will take several minutes to run Id like to include a progress bar which starts when the button is pressed and finishes when the process is finished and the dialog saying ‘Done’ is thrown up.

I’ve been fiddling with this sort of thing but am having no luck. Could somebody please help me?

script updater
	property parent : class "NSObject"
	property kProgressBar : missing value
	
	on buttonpress_(sender)
		kProgressBar's startAnimation_(kProgressBar)
		do shell script "say 'good morning everybody'"
		display dialog "Done"
		
	end buttonpress_
	
	kProgressBar's stopAnimation_(kProgressBar)
	
	
end script

thanks D

What are you seeing in your program? Does the progress bar not animate? Are you using an indeterminate progress bar or a determinate one? If indeterminate, then you might want to try using threaded animation: kProgressBar’s setUsesThreadedAnimation_(1). Also, move the stopAnimation message into your buttonpress method.

I think that in any case, if your shell script is really going to take a couple of minutes, an indeterminate progress bar might not be the best thing – that’s a long time to leave the user wondering what’s going on. You might want to also throw up an alert notifying the user that it will take a couple of minutes. A determinate progress bar would be better, but I don’t know how you would update it unless you can break your shell script up into multiple pieces and update the progress bar in between calls.

Ric

Thanks for your advice, I have moved the stopAnimation command. As it turns out the main problem was bad wiring in IB. Now I have wired the kProgressBar as an outlet to the Updater NSObject things are working!

A determinate progress bar would be nice but the main purpose of the script is to update the locate database, a process which I think probably has an unguessable / indeterminable duration. Am I correct in thinking this?

many thanks for reply.

My working code now looks like:

script updater
	property parent : class "NSObject"
	property kProgressBar : missing value
	
	on buttonpress_(sender)
		kProgressBar's startAnimation_(kProgressBar)
		do shell script "say 'good morning everybody'"
		kProgressBar's stopAnimation_(kProgressBar)
		display dialog "Done"
	end buttonpress_
	
end script

You’re probably correct, but since I don’t know what the locate database is, I can’t really say.

Ric