Is it possible to write a python program (that I will run as a daemon I think) that can detect when osx goes to sleep and also when it resumes from sleep?
Apologies if it sounds like I’ve not researched this – I’m well out of my comfort zone and unsure if I need to delegate from python to something written in C that can report this, or that’s unnecessary.
There’s tools to do this in IOKit — specifically, a callback registered with
IORegisterForSystemPower()will be called right before the system sleeps, and right after it wakes up.You may want to check out bb’s
sleepwatcherdaemon, which can call commands you specify when a variety of events occur, including system sleep/wake, as well as a variety of other events (display sleep/wake, system idle, shutdown…).