Writing a Cocoa App like MacJanitor!!

Discussion in 'Mac Programming' started by Littleodie914, Jan 30, 2006.

  1. macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #1
    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
     
  2. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #2
    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.
     
  3. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #3
    There is a lot of discussion, code and so on on CocoaDev for just this sort of thing.
     
  4. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #4
    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
     
  5. thread starter macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #5
    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];
    }
     
  6. macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
  7. thread starter macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #7
  8. macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #8
    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...
     

Share This Page