Great idea and implementation! If you are hesitant to install this for any reason, you can accomplish the same thing with this one liner:
sudo bioutil -ws -u 0; sleep 1; sudo bioutil -ws -u 1
Edit: here's a shortcut to run the above and then lock your screen. You can give it a global keyboard shortcut in the Shortcuts app.
https://www.icloud.com/shortcuts/9362945d839140dbbf987e5bce9...
Hook this to a lid angle below 30° trigger in https://lowtechguys.com/crank and you can easily make it run on a simple lowering of the lid