I’m working on a Mac app that will optionally provide the ability to install some extra software that’s in apple package format. This package requires elevated (root) privileges to install, and instead of bothering with a helper tool or AuthorizationExecuteWithPrivileges(), I figured it would be easier to use NSTask to call /usr/bin/open or even /System/Library/CoreServices/Installer.app/Contents/MacOS/Installer with the path to the package and let it handle the user authorization.
So, it works all fine and dandy, but the Installer window does not appear at the front of the stack, nor is it ever key. I can orderOut the calling window before launching the task and that helps with the ordering, but the key is really going to be, well, making it key.
Should I just go ahead and implement Apple’s BetterAuthorizationSample since I’ll probably have to use it at some point in the future, and since it will make be a better person for having tried?
There are two variables which determine which window is key. One of those is a setting within an application which determines which of its windows is in focus, and the other is which application is active. Hiding windows in our own application will make the installer visible, but it won’t become key unless you make the installer application active. You have a few options for doing this.
First, you could deactivate your application using:
Next, you could find the
NSRunningApplicationfor the installer and activate it:But in your case I would recommend using
NSWorkspaceto open the installer for you, instead of starting it throughNSTask.NSWorkspacewill automatically deactivate your application, so you don’t have to, you get feedback about whether the file opened successfully, and the application to open it with is automatically chosen.