How to start Mach-O file - macos

I have created a small Cocoa application and built a Mach-O file using cross-platform tools. It is working Ok.
If I bring the Mach-O file to Mac (MacBook Pro OSX 10.11) it appears with Terminal icon in the Finder. If I double-click it, it opens unix Terminal window and starts the application from within the Terminal. Once my app starts, it opens its own window and works as expected. Of course, the Terminal window besides the application looks ugly. How do I make it start without opening the Terminal window?
My guess there should be some flag in Mach-O file to indicate it's a GUI application and doesn't need a Terminal, but I haven't found anything like that.

Related

MacOS screencapture only taking images of Desktop

I created an applescript shortcut to take screenshot (larger usecase). But the resulting saved screenshot is only of the Desktop, even if other applications are in focus. Here is my applescript snippet
do shell script "screencapture -dxi /private/tmp/test.png"
I am also compiling with osacompile and launching the app through the Finder. I've also checked file directory and permissions (+ System Preferences) while everything checks out.
If I was to execute this command from the terminal then it would run as expected. My guess is that by running the app by double-clicking int the finder then a different user is used and results in inadequate permissions.

OSX - How to show no terminal window when I launch my executable?

I'm developing a C application for OSX with gcc.
When I launch my application with double click in finder a terminal window is shown. My application only does some basic operations and exits. Is there a way to prevent the terminal window from showing up?
In win32 I can set the subsystem to WINDOWS in PE executable. Is there something analogous for OSX?
Thanks in advance.

What is the difference between launching a Mac OS X app via the Finder/open and executing the app binary directly?

I'm experiencing an issue with a Qt app on Mac OS X 10.10.5, whereby a QFileDialog will not close properly when canceled. While this may be a bug in Qt, I only see this bug when running the app as a normal user would, e.g. opening it in the Finder (or via command line open). If I launch the app via Xcode or by calling the binary directly, there is no issue.
Launch the app via calling the binary directly on the command line or within Xcode, e.g. ./MyApp.app/Contents/MacOS/MyApp
Launch the app via the Finder or open, e.g. open ./MyApp.app
What are the differences between these two methods - and how does it impact a running application?
The major difference is the working folder. You don't have any control over what it is, but it will be different between the two invocations.
What directory are you showing the QFileDialog in? You should probably start in a well-defined place, like the user's home.

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?
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.

Why does my Firemonkey app open a terminal window on OSX but not on Win32?

I created a simple testbed app in Delphi XE2, and compiled both a Win32 and OSX version of the application.
I zipped up the OSX version, along with a copy of the libcgunwind dylib runtime file and copied this files to a Mac i have access to.
When I unzipped the file, the mac recognized my OSX application and I double clicked it.
This, in turn, opened up a terminal window for some unknown reason along with my simple app's form.
The application itself ran and behaved just fine, but I'm curious why a terminal window would open up on the Mac?
There is a free tool available for Delphi XE2 that will create the OSX deployment app bundle for you, from Windows, without the need for PAServer.
http://enesce.com/delphiosx_bundler
Check the readme for instructions.
IIRC this happens if you execute the binary directly instead via a bundle
Lazarus/FPC apps had the same problem. IIRC the directly executed binary also didn't get events under those circumstances, but those apps were Carbon based. That problem also went away when running via a bundle setup (which is pretty much a manifest, a few dirs and a symlink)
Your application needs to be run from the application bundle. If you run it directly, you'll get the side effect of seeing the terminal window with the command line that is running the application.
You'll want to read more about Application Bundles.
If you're using PAServer, after you run the program for the first time on the Mac, look in the following folder on the Mac for the application bundle:
/Users/[username]/Applications/Embarcadero/PAServer/scratch-dir/[profilename]
If your project is named Project1, you'll see an application bundle in that folder named Project1.
If you read the above wiki article, you'll know that Project1 has a "hidden" extension of .app, and the whole thing is really a folder with all of the required files to run the application.
To the Mac OS user, the application bundle appears as a single program file, complete with an icon. The user can double-click the application bundle to run the application, drag it to their dock, etc.
The application bundle will have the Delphi icon by default, but you can replace it with your own icon. On the Mac, simply right-click on the application bundle in Finder, and select Show Package Contents. In there, look in the Contents/Resources folder for the .icns file.
Use the Icon Composer application that was installed with XCode to create your .icns icon file from existing image files.
Peek around inside at the rest of the contents. You'll see the required dylib, your program file, and the Info.plist file, which is a text file with things like application IDs, signatures, and other important things.

Resources