So I've got an app that can run both as a UI app and as a command- line tool. Which mode it runs in is governed by a command-line argument; if the app is just double-clicked, it runs with UI, but if it is launched with the argument "-nohead" it runs as a tool. This has worked great for some time now. (The reason, if you're wondering, is that this is a scientific model that needs to run with graphs and whizzy output interactively, but also needs to run in a batch mode on a computing cluster.) My modified main() to accomplish this:

int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        NSProcessInfo *processInfo = [NSProcessInfo processInfo];
        NSArray *arguments = [processInfo arguments];
        
        if ([arguments containsObject:@"-nohead"])
        {
                int retval = AKRunHeadless();
                
                [pool drain];
                return retval;
        }
        else
        {
                [pool drain];
        
                return NSApplicationMain(argc, (const char **) argv);
        }
}

However, I just added the ability for the app to dump some output into PDF files when it's running on the command line. Apparently the fact that I'm accessing AppKit makes the system switch from considering my app to be a command-line tool, in this case, to considering it to be a GUI app. The consequence is that the dock adds an icon for my app. However, that run of the app finishes within a moment (since the image is dumped at the end of the run), so the icon goes away; but a new run of the app starts after that, so the icon comes back. And on and on. I'm actually running 16 instantiations of the app at a time (8-core Mac Pro with hyperthreading :->), so the dock thrash is rather spectacular, and must be burning a bit of CPU, too.

Any way to suppress this? The only way I know of involves a flag in the app's plist, which doesn't work here because I still want the app to be able to run as a GUI app, too. Basically I just want to suppress whatever piece of code is saying to itself "my gosh, it just made a view, it must be a GUI app!" I had been under the impression that avoiding calling NSApplicationMain() was sufficient to keep this from happening, but apparently not.

  Thanks in advance...

Ben Haller
McGill University

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to