Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Littleodie914

macrumors 68000
Original poster
Jun 9, 2004
1,813
8
Rochester, NY
Hey guys, I've decided to try and write a program like MacJanitor to give to my Unix teacher (who also uses a Mac) just for fun. I'd also like to do it just for my own use to improve my programming skills.

I have the general layout design finished in IB, but don't know how to run terminal commands from inside Xcode. Also, it would be nice to add a little progress bar type thing so that the user knows how far the program is from completion.

Can anyone here either provide good resources/tutorials as to how to learn these specific techniques, or post replies with snippets of code that might lead me in the right direction? (Example code, etc.) Thanks a bunch! :D
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,629
Western US
Littleodie914 said:
Can anyone here either provide good resources/tutorials as to how to learn these specific techniques, or post replies with snippets of code that might lead me in the right direction? (Example code, etc.) Thanks a bunch! :D
Read the Apple documentation related to NSTask, NSPipe, NSFileWrapper, and NSProgressBar. Sorry I don't have time to elaborate! There is definitely example code available for running UNIX commands from Cocoa, use Google.
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
If you have to have administrator rights for anything then you'll come up against Apple's Authorization mechanism (it's pretty much Carbon only - the Cocoa wrapper's crap). It's a load of fun....not
 

Littleodie914

macrumors 68000
Original poster
Jun 9, 2004
1,813
8
Rochester, NY
Okay, I've dropped my expectations for what this program will amount to, and I'm now just going to try and write a program (from scratch) that will send the "uptime" command and display the results. I know I'm doing all of this wrong, but what I do know how to do is...

Create the task using NSTask, assign the command (but I don't know where uptime is?), create a pipe with NSPipe, send the task arguments, and launch the task. That's about it. I've looked around at the documentation, but learning both of the pieces (Task and Pipe) is a bit daunting.

Now that I've got an easier program, do any of you guys have any pointers as to where to look from here? Here's all I've got: (I know some of it is incorrect and incomplete, but it's my general understanding of what I want to do.)

Code:
- (IBAction)daily:(id)sender
{
	mytask = [[NSTask alloc] init];
	piper = [[NSPipe alloc] init];
	[mytask setLaunchPath:@"uptime"];
	[mytask launch];
	[resultsbox setStringValue:piper];
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.