Daemons can’t reliably connect to the window server, and thus shouldn’t use APIs like Core Graphics. You can learn more about this in Technote 2083 Daemons and Agents (which that technote could do with an update, the discussion of the macOS’s architecturally fundamentals is still sound).
There’s two supported ways to talk to the window server from a pre-login context:
Via a pre-login launchd agent, as illustrated by the PreLoginAgents sample code
From a non-privileged authorisation plug-in
The former is probably what you want; the latter is useful if you need to run synchronously with respect to the login process.
IMPORTANT If you create a pre-login launchd agent, carefully read the read me for the PreLoginAgents sample code. Specifically, when working with Core Graphics events, you may run in to a known bug (r. 5636091).
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"