PyInstaller OS X app runs from command line, but not Finder window - macos

I have an application bundle created with PyInstaller on OS X. If I double click the .app bundle in Finder, the application tries to launch, then terminates. No further information is given in the console, other than the application quit.
But if I launch the app executable from the terminal (i.e., ./Contents/MacOS/MyApplication, it works perfectly fine. This seems to be the same behavior experienced in this issue: OSX app built with python quits immediately if app bundle is executed from finder but runs fine from command line, but the marked solution there isn't particularly helpful.
I suspect this is indeed related to an environment or path issue. But I'm not sure how to fix it. Should something be specified in the info.plist file maybe? Any guidance would be greatly appreciated.

This is most likely due to a bad assumption about the working directory. When you launch from the Finder, the working directory may well be / (depends on OS X version), which is not writeable. If your app writes to the current working directory then you should probably set the working directory to somewhere sensible at startup.

Related

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.

How to tell finder that my application is installed?

I am working on a cocoa application. I see a strange behaviour on Mac OS 10.6.8..!
My Cocoa application has an Automator action inside it. I want it to be listed in Automator as soon as I install it.
The conditions are as follows:
1. After installation, user should not go to the installed path.
2. User should not launch the application.
I mean, I am seeing this bug only for above mentioned situations. If I go to the installed folder, or launch the application, the automator app gets listed.
I didn't see this defect on Mac OS 10.7.5 or Mac OS 10.8.2..
Also I tried touch command via terminal just in case thinking that if any kind of Access updating is required and all. But that wasn't the case.
Any suggestions? Can I run any kind or Shell/Applescript while installing [After installation of the application] so that I can list the automator action in automator?
Any advice or help would be great!!
You can have a .txt file with the below script and then you have to add postflight script when taking .pkg file in Package Maker.
open "/Applications/yourAppName.app"
Try this Terminal command.
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister .../Whatever.app
You shouldn't hard-code the path, though, as users sometimes stick apps in weird locations (citation: I do it :).

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.

prohibitory sign on application icon (broken folder) on Snow Leopard

I have prepared a disk image with my application,which i want to install in Applications folder. When i copy the application from the disk image to the applications folder, i see that first it gets generic application icon (sometimes my application icon with a prohibitory sign (or broken folder) ). It becomes executable application after a couple of seconds (some 10 seconds)
I wonder if somebody has experienced something similar?
EDIT: On my customer computer with Snow Leopard the application stayed with a prohibitory sign (broken folder) . How do i fix it? It worked on Leopard
Yes this happens to me too. That is (supposed to be) the appearance of an app that cannot run on your particular platform, e.g. an Intel program on a PPC machine. Not sure why it does it to legit apps, but it seems to go away after a while (perhaps after it is run once?)
As I suspected it was a permissions problem. When build an installer with a Packager all items have to have a root as owner and wheel as group for permissions.
Why it stays that way is another question (perhaps related to caching?), but the reason for a copied application temporarily displaying as broken is simple: it is broken. That is, while it is being copied, it is incomplete, and therefore "broken". When the copy is complete, the application icon should update to indicate a good application.
If it doesn't this might be because the copy failed for some reason, or because the intermediate result is cached. In that case try refreshing by simple closing the Finder window and reopening it.

Resources