Question

I'm trying to package my binary in a minimalistic app bundle. But I'm seeing some strange behavior with the result.

My bundle has this minimal structure:

$ ls -R HelloWorld.app
Contents

HelloWorld.app/Contents:
Info.plist MacOS      PkgInfo

HelloWorld.app/Contents/MacOS:
helloworld

helloworld is a C binary compiled from:

#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv) {
    while (1) {
        printf("Hello world!\n");
        sleep(2);
    }

    return 0;
}

Info.plist contains:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleExecutable</key>
    <string>helloworld</string>
    <key>CFBundleIdentifier</key>
    <string>com.litl.helloworld</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>HelloWorld</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0.0</string>
    <key>CFBundleVersion</key>
    <string>20</string>
    <key>LSMinimumSystemVersion</key>
    <string>10.6</string>
    <key>LSUIElement</key>
    <true/>
    <key>LSBackgroundOnly</key>
    <true/>
</dict>
</plist>

Now for the strange behavior. When I run

open ./HelloWorld.app

The command hangs for about 30s. After that I can confirm that the helloworld binary is running. However its standard output does not show up in Console.app. If I launch this bundle programmatically (NSWorkspace sharedWorkspace] launchApplicationAtURL...) the call succeeds, but the binary exits immediately (I can see in the console it exited with error code 2).

This is on OS X 10.9.2.

What am I doing wrong?

Was it helpful?

Solution

You need to register with Cocoa to mark your application as responsive and 'ready'. If you would enable the dock icon, it means that it stops to bounce. In your case, if you hide the icon from the dock, you still need to register with Cocoa.

You can do that e.g. by creating a NSApplication class. See here for some low level deails.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top