2 Replies
      Latest reply on Apr 9, 2019 1:44 AM by eskimo
      Rulovic Level 1 Level 1 (0 points)

        Hello all,

        I would like to do some actions in my app(specifically writing some logs) when laptop is waken up/slept due to lid opening/closing.

        How can I detect that? Is there Notification emitted or API I can check to achieve that?

        I have read I could use Advanced Configuration and Power Interface (ACPI) but I havent found a lot of documentation.

        Thanks in advance

        • Re: Detect if lid is opening/closing
          Claude31 Level 8 Level 8 (9,205 points)

          Could this provide a first hint at a solution ?


          h ttps://unix.stackexchange.com/questions/11724/how-to-detect-a-laptop-hibernate-resumeclose-lid-open-in-osx-from-a-bash-scrip


          Good luck.

          • Re: Detect if lid is opening/closing
            eskimo Apple Staff Apple Staff (13,935 points)

            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"