What I have is NSTask running a long premade shell script and I want the NSProgressIndicator to check on how much is done. I've tried many things but just can't seem to get it to work. I know how to use it if the progress bar is indeterminate but i want it to load as the task goes on.
Here is how I am running the script:
- (IBAction)pressButton:(id)sender {
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/bin/sh"];
[task setArguments:[NSArray arrayWithObjects:[[NSBundle mainBundle] pathForResource:@"script" ofType:@"sh"], nil]];
[task launch];
}
I need to put a progress bar in that checks the progress of that task while it happens and update accordingly.
Here is an example of an async NSTask running a unix script. Within the Unix script there are
echo
commands that send back the current status to standard error like this:echo "working" >&2
This is processed by notification center and sent to the display.
To update a determinate progress bar just send status updates like "25.0" "26.0" and convert to float and send to the progress bar.
note: I got this working after alot of experimenting and by using many tips from this site and other references. so I hope it is helpful to you.
Here are the declarations:
Here are the main program modules: