Apparently this can be done listening to SystemConfig:
https://developer.apple.com/forums/thread/113446