Search code examples
macosexecutableosx-mountain-lionnsbundle

Behaviour of OS-X Application Bundles


How does being inside an application bundle affect how the binary executable runs?

To explain, I compiled Emacs for Mountain Lion. This produces a binary executable, and also an application bundle, Emacs.app, that contains the exact same binary (same content, according to diff), plus other resources.

If I run the binary itself from the terminal (or finder):

  • Emacs starts, processes my init file correctly and looks good.
  • But the application menu still says "Terminal" and
  • keyboard input goes to the terminal not to Emacs.
  • Also the red traffic-light button gets sent to Emacs (Emacs says it has nothing to save) but does not terminate the process.

In contrast, if I run the Emacs.app, Emacs runs as expected. Can anyone explain this difference for me please?


Solution

  • When you launch an .app bundle, the Info.plist at the root of the folder configures many OS specific behaviors.

    https://developer.apple.com/library/mac/#documentation/General/Reference/InfoPlistKeyReference/Introduction/Introduction.html

    You can launch any native executable this way and have the same behavior.