PDA

View Full Version : Writing a Cocoa App like MacJanitor!!




Littleodie914
Jan 30, 2006, 06:27 PM
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
Jan 31, 2006, 12:11 AM
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.

robbieduncan
Jan 31, 2006, 02:22 AM
There is a lot of discussion, code and so on on CocoaDev (http://www.cocoadev.com/index.pl?WrappingUnixApps) for just this sort of thing.

caveman_uk
Jan 31, 2006, 03:00 AM
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
Jan 31, 2006, 01:35 PM
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.)

- (IBAction)daily:(id)sender
{
mytask = [[NSTask alloc] init];
piper = [[NSPipe alloc] init];
[mytask setLaunchPath:@"uptime"];
[mytask launch];
[resultsbox setStringValue:piper];
}

jeremy.king
Jan 31, 2006, 01:39 PM
http://developer.apple.com/documentation/Cocoa/Conceptual/OperatingSystem/index.html#//apple_ref/doc/uid/10000058i

Littleodie914
Jan 31, 2006, 02:44 PM
http://developer.apple.com/documentation/Cocoa/Conceptual/OperatingSystem/index.html#//apple_ref/doc/uid/10000058iAh thank you so much! I looked through apple's development pages but could only find API's, which definitely didn't help. I think the page you provided is just what I'm looking for!:D

jeremy.king
Jan 31, 2006, 02:52 PM
I think the page you provided is just what I'm looking for!:D

Glad to help, but really all I did was a quick search on http://developer.apple.com for NSTask and it was one of the first results...