Hi,
We are seeing an issue on 10.14 build which is as followed:
When we try to get list of current running applications on Mac using API:
[NSWorkspace.sharedWorkspace runningApplications], the list of the applications running is always restricted to:
<NSRunningApplication: 0x7fa839200b70 (com.apple.ViewBridgeAuxiliary - 44824)>,
<NSRunningApplication: 0x7fa839200cb0 (com.apple.ViewBridgeAuxiliary - 44964)>,
<NSRunningApplication: 0x7fa839200da0 (com.apple.CoreSimulator.CoreSimulatorService - 44976)>,
<NSRunningApplication: 0x7fa839200e90 (com.apple.WebKit.Storage - 45251)>
instead of including all of the running applications.
The service which is trying to get the list of applications is running as launchd daemon and hits this problem.
However, if we call the same API using the command line tool, it gives the complete list of applications.
This API works fine on builds prior 10.14.
Could you please let us know how can we fix this problem?
Thanks.
This is not expected to work. That’s because
NSWorkspace
is part of AppKit and AppKit is not daemon safe. If you call it from a daemon context, there’s no guarantee how it will behave.
I strongly recommend that you read Technote 2083 Daemons and Agents. While it’s quite old, it’s still largely accurate and it explicitly describes the background to the issue you’re seeing.
You wrote:
This API works fine on builds prior 10.14.
No it did not. It seemed to work but you just hadn’t noticed the edge cases. For example, it might have returned the running apps from one GUI login session, but macOS supports multiple GUI login sessions (via both Fast User Switching and remote access) and it was undefined which one you’d get.
How you proceed here depends on your goals. What do you need a list of running applications for?
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"