Could this provide a first hint at a solution ?
The power management APIs, like
IORegisterForSystemPower, tell you about the system’s power state, which is not directly tied to the lid state. A MacBook has be asleep with the lid open and awake with the lid closed.
As far I know there’s no way to get the lid state directly.
Share and Enjoy
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"