I think someone also made this for MacBooks: https://github.com/samhenrigold/LidAngleSensor