I'm an old programmer teaching myself macOS and making tools for my own use.
I've got an app working that launches a GUI conditionally, but when it launches the GUI, the system prints logging info to stderr. How can I prevent that programmatically?
I'm launching the GUI like this:
NSApplication.shared.run()
And the logging info I don't want that is coming from the OS looks like this:
1 HIToolbox 0x00000001902e05c8 _ZN15MenuBarInstance22EnsureAutoShowObserverEv + 120
2 HIToolbox 0x00000001902e0188 _ZN15MenuBarInstance14EnableAutoShowEv + 60
3 HIToolbox 0x0000000190283310 SetMenuBarObscured + 372
4 HIToolbox 0x0000000190282ee8 _ZN13HIApplication15HandleActivatedEP14OpaqueEventRefhP15OpaqueWindowPtrh + 172
5 HIToolbox 0x000000019027cfcc _ZN13HIApplication13EventObserverEjP14OpaqueEventRefPv + 296
6 HIToolbox 0x0000000190243cd0 _NotifyEventLoopObservers + 176
7 HIToolbox 0x000000019027c96c AcquireEventFromQueue + 432
8 HIToolbox 0x000000019026be0c ReceiveNextEventCommon + 712
9 HIToolbox 0x000000019026bb2c _BlockUntilNextEventMatchingListInModeWithFilter + 72
10 AppKit 0x0000000189e18424 _DPSNextEvent + 632
11 AppKit 0x0000000189e175b4 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 728
12 AppKit 0x0000000189e0b9e4 -[NSApplication run] + 464
13 macos-cond-gui 0x0000000104cd0764 main + 2148
14 dyld 0x000000018678fe50 start + 2544
I've tried setting the environment variable OS_ACTIVITY_MODE to disable, but this makes no difference. I verify in my code that it can see that it's set. Could it be that app.run() creates a new process that doesn't have the same env vars?
I realize I can redirect stderr. I'm looking for a programmatic solution so the app doesn't force this onto the user. I also will want to output my own messages to stderr that I won't want hidden.