SCDynamicstoreCopyConsoleUser returns an empty string

consoleUser = SCDynamicstoreCopyConsoleUser(NULL, &uid, &gid);

the string is empty, but not NULL. uid and gid are set properly.

Any idea why this would happen? NB: it only happens from a LaunchAgent, for some reason; if I isolate the code in question, and run it via CLI, it works exactly as expected. And it only seems to happen for one person -- but for him, it happens on both Intel and Apple Silicon.

SCDynamicstoreCopyConsoleUser is a very thin wrapper around the dynamic store. You can see the code here.

AFAICT the only way to get this failure is if the dynamic store itself contains that info.

What are you using this for in a launchd agent? Are you trying to determine if the user running your agent is the console user?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Yes, due to the IPC being used by the other parts of the suite using a broadcast mechanism, instead of point-to-point. Some of the actions, as a result, should only be taken if the current user is on the console. (E.g., trying to load the network extension.)

should only be taken if the current user is on the console.

And you want to specifically exclude folks who have started a GUI login session via screen sharing?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

We are ignoring that for now, although now I am wondering if that's the cause. But... the stand-alone program worked, so I'd ruled that out as a possibility. (Both this person and I generally access our machines via screen sharing, mind you.)

(Sorry, I should clarify: both the user in question, and I, log into the systems in question using screen sharing -- for me, it's in a different room, up some stairs, and I am lazy. I just rebooted it and made sure that if I log in only via screen sharing, it works for me. What we're ignoring is is multiple simultaneous console logins, which I can never remember how to do.)

SCDynamicstoreCopyConsoleUser returns an empty string
 
 
Q