NSWindow not Activating - cocoa

I create a window in a helper tool that runs in the background (it's not an app bundle with a .nib and Info.plist, but a plain executable). When -makeKeyAndOrderFront: is called, the window is displayed but it does not "pop" out like an active window.
Can this be fixed?
Regards,
Erik

You should wrap the helper tool as a regular .app bundle with at least Info.plist. Then the problem goes away. A GUI app in OS X needs to have an Info.plist to receive events correctly.
The way a GUI app misbehaved if not in an app bundle has never been clear to me. If I remember correctly, it changed over time, depending on OS X's versions. I think it behaved worse in previous versions of OS X. For example, the window is shown but I couldn't click any UI inside it.
Many people who compiled a program in a cross-platform toolkit faced this problem, see e.g. this discussion here in the WxWidgets wiki. Apparently, OS X doesn't mark a program not within an .app bundle as a foreground-able app, which causes your problem. You can use TransformProcessType from your binary not inside an .app bundle to make a foreground-able app to solve your problem, but that's not a documented/intended usage of this function.
So, just wrap it in an .app bundle.
Update:
This "foreground-able-ness" is controlled by the activationPolicy of an app, see this doc on NSApplication. Found the info on this post on Cocoa with love.

Related

Macos app displays view in Xcode, but is totally blank when launched outside of Xcode

I'm working on a small macos app, which I'm building with storyboards/interface builder in Xcode 10.2.1 on MacOS 10.14.5 (though I've set a deployment target of 10.13, if that matters).
When I run the app within Xcode, i.e., by hitting the "play" button, it loads up just fine and is visible and operates.
However, when I "archive" it to a freestanding executable and then try to run the app from the hard drive, it opens up on a blank screen. (See screenshots below.)
I've cleaned the build folder. I've also made sure to clear any/all build warnings and autolayout constraint warnings.
Here it is, running perfectly fine within xcode:
And here it is, displaying nada when run on its own:
The app uses no third-party libraries, no bundle assets, and only has one ViewController---nothing fancy at all happening here. The only weird UI thing that I'm doing is that there's a very small webview in the bottom-right corner that I'm using as a hack to load js-based web content (the mysterious white dot in the working screenshot).
Ok, I figured this one out myself, so for the purposes of google/if someone else has this problem: there seems to be a bug in WKWebView of some kind, adding it to IB kills everything else in the view. (Or maybe this is intended, and WKWebView requires it's own independent view? Dunno.)
The solution is to create it programmatically and never put it in the view at all. You can still load web content in the background, scrape information from pages, etc. without it ever being part of a view.
Not only WKWebView, also AVPlayerView should not placed int IB, too.
it cause same result.

Create custom right-click menu for OS X app, developed on Linux

I am creating an app for Mac OS, but it is being built on Linux. Because of this, I am not able to use tools such as Xcode, and I am not developing in swift. Rather, the .app directory is being put together according to Apple's documentation, and the entrypoint/executable of my app is a shell script.
I need to customize the menu which appears when you right click on the app (either on the dock icon or in Finder). Is there a way to do this, without using cocoa, etc.?
The menu I believe you are referring to is called "Services".
In order to add a menu item there for your application you would create a script to enable including it there. Xcode isn't needed or required, however, you'll need to know at the very least some basic AppleScript or Javascript to accomplish what you want. (see examples from the link)
↳ Mac Automation Scripting Guide

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.

Ruby Shoes won't start in Leopard

So I wanted to try doing some easy Ruby GUI programs using Ruby Shoes. I downloaded Shoes 3 for OS X, opened the dmg and installed it to the Applications folder. When I click on the icon in the folder, or drag a source code file to it, the icon briefly appears in the dock and bounces, and then disappears without anything running. So I can't use it. The computer I'm trying to run it on is running Leopard - is that the problem?
Have you tried building shoes 4? You might want to check it out, and check the readme. I can confirm it working on my 10.6 mac, which is about as close to leopard as you can find. Just try the directions for *nix and it should work, as far as I know.

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