Building commandline tool with GUI

Discussion in 'Mac Programming' started by SP-NewToMac, May 11, 2009.

  1. SP-NewToMac macrumors newbie

    Joined:
    May 11, 2009
    #1
    Hi,

    I want to build an exe for Mac that has a few dialogs. I do not want to create an application as it creates menubar, and application structure. The exe will eventually get integrated into other products.

    I tried following code in a FoundationTool project -

    int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    // insert code here...
    NSLog(@"Hello, World!");
    NSApplication *app = [NSApplication sharedApplication];

    if ([NSBundle loadNibNamed:mad:"SendDmp.xib" owner:app])
    {
    NSLog(@"Nib loaded");
    [app finishLaunching];
    } else {
    NSLog(@"Nib Load failed -- ");
    }
    [app run];

    [pool drain];
    return 0;
    }

    The xib file is included in the project, but it is failing to load the file. I tried copying the xib file to the debug folder thinking its not finding the file, but nothing changed. The application runs but I don't see the form.

    Please help.

    Thanks
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    A Foundation Tool doesn't create a .app bundle, which is what you need to store nibs in (unless you store it in the same folder as the executable, but this isn't Windows :p). So I'd suggest recreating the project as a Cocoa Application, and then you can rip out the MainMenu.nib part and put in your nib instead so it's copied to the .app's Resources folder.
     
  3. SP-NewToMac thread starter macrumors newbie

    Joined:
    May 11, 2009
    #3
    Thanks for your quick response and for the tip on ripping out mainmenu.nib. Didn't know that was possible. This is my first attempt at Mac development, so please bear with me. :)

    This app will be included in other products that will have their own bundles (localization etc). If I create my own app, how do I integrate it into their directory structure? Can I store my bundles into the main product's folders or does it have to be within my project folder.

    This probably is a bigger question that I will have to figure out by myself. But any helpful pointers will be appreciated.

    Thanks again.
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    Yes. There are several ways to do this, but it depends on how you have the main product's project setup.

    You might want to read up on Xcode's Build Phases. You can setup a Copy Build Phase to copy your command-line tool's .app into your main product's .app directory (either into its Resources or Executables folder). Then the main app can use the NSBundle/CFBundle API to find that tool and launch it.
     

Share This Page