Stopping Karabiner-Elements on lock and restarting it on unlock fixes sleep issues on MacBooks. This script effectively ensures that the system enters sleep mode properly instead of staying active due to Karabiner’s background processes.
Ensure you have PyObjC installed, as it is required to handle macOS system events.
pip3 install pyobjc