NSRunningApplication activateWithOptions does not work on Sonoma

Hello,

Our application uses following code to activate itself:

void BecomeFrontMostApp() {
    
    @autoreleasepool {
        if ([NSApp isActive] == YES) return;
        [[NSRunningApplication currentApplication] activateWithOptions: NSApplicationActivateIgnoringOtherApps | NSApplicationActivateAllWindows ];
    }
}

Code works on Ventura and previous OS versions but not on Sonoma. On Sonoma application does not come to foreground but instead dock icon starts jumping same way when calling:

[NSApp requestUserAttention: NSCriticalRequest];

And activateWithOptions returns false.

I checked activationPolicy on the app running on Sonoma - it is NSApplicationActivationPolicyRegular

Any ideas how to fix this appreciated.

Answered by JWWalker in 768832022

I'm surprised that you say it worked in Ventura, because in my testing, NSApplicationActivateAllWindows has not worked since at least 10.15. I filed FB11974786 about it. I worked around it by using the old Carbon function SetFrontProcessWithOptions, which is deprecated but works.

Accepted Answer

I'm surprised that you say it worked in Ventura, because in my testing, NSApplicationActivateAllWindows has not worked since at least 10.15. I filed FB11974786 about it. I worked around it by using the old Carbon function SetFrontProcessWithOptions, which is deprecated but works.

NSApplicationActivateIgnoringOtherApps is deprecated in Sonoma so it seems intentional.

I understand the theory that forcing yourself active can be abused and bad but I've needed to do it to workaround macOS bugs before. I use NSApplication +activateIgnoringOtherApps: to workaround some bugs in macOS before...but that's also deprecated and I haven't tested but I assume that that method doesn't work either anymore.

Curious why are you calling that inside an autoreleasepool?

NSRunningApplication activateWithOptions does not work on Sonoma
 
 
Q