2

There are a lot of system' events in OSX. I would like to start my [python] script on some of them e.g. on power supply on. How can I do such hook?

davejal
  • 6,009
  • 10
  • 39
  • 82
  • I don't understand what even "on power supply on" would mean. There is no generic "every possible system event" callback system. (Is "we received a packet" a system event? "The user pressed a key?" "The clock ticked?" "The Carry flag was set on the processor?") You're going to have to indicate what system events you mean. – Rob Napier Jan 25 '16 at 21:51
  • I need to start my script avery time when user connects a power supply (from nothing to connected state) like events in Debian when it is new IP assigned. – Paul Katurov Jan 25 '16 at 22:31
  • To do that with an existing tool, see http://www.controlplaneapp.com. If you want to build your own in IOKit, take a look at how Control Plane does it internally. https://github.com/dustinrue/ControlPlane/blob/master/Source/AttachedPowerAdapterEvidenceSource.m (though I believe they poll). See also `pmset` which you can use to get the current status from the commandline, and https://developer.apple.com/library/prerelease/mac/documentation/DeviceDrivers/Conceptual/AccessingHardware/AH_IOKitLib_API/AH_IOKitLib_API.html IOKitLib, which can generate notifications. – Rob Napier Jan 25 '16 at 23:32

0 Answers0