cocoamacosuser-agentnib

Is it possible to hide the dock icon programmatically


Is it possible to hide dock icon programmatically on demand. I know one way by which defining property "Application is agent (UIElement)" in plist we make the cocoa app as user agent. But this result in hiding the dock icon permanently.

I am looking for a way where i can control visibility of dock icon. Any idea ?


Solution

  • Unfortunately not. You can transform a background-only app to a foreground app using the TransformProcessType() function but you can't go from a foreground app to a background app.

    Here's how to go from background to foreground:

    ProcessSerialNumber psn = { 0, kCurrentProcess }; 
    OSStatus returnCode = TransformProcessType(&psn, kProcessTransformToForegroundApplication);
    if( returnCode != 0) {
        NSLog(@"Could not bring the application to front. Error %d", returnCode);
    }