SCContentFilter init error

When I try to initialize SCContentFilter(desktopIndependentWindow: window), I get a very weird error:

Assertion failed: (did_initialize), function CGS_REQUIRE_INIT, file CGInitialization.c, line 44.

This is a brand new CLI project on Sonoma 14.2.1. Any ideas?

I'm having the same issue on 14.3

Did you ever find a workaround?

I managed to find a workaround:

Call CGMainDisplayID(); before initalizing the filter. Tested both in Swift and Objective-c.

According to https://github.com/JXA-Cookbook/JXA-Cookbook/issues/27#issuecomment-277517668 its because Core Graphics is not initialized, and CGMainDisplayID does this.

SCContentFilter init error
 
 
Q