Is it possible to make 16.04 hibernate on lid close? [duplicate]

I recently updated to 16.04 (64 bit) and I'd really love to be able to make my laptop hibernate on closing the lid. I'm able to successfully hibernate by typing sudo pm-hibernate into terminal but I tend to forget to do this when tossing my laptop in my bag and then I pull out a dead computer.

I've followed the directions here: http://ubuntuhandbook.org/index.php/2016/05/ubuntu-16-04-shutdown-hibernate-your-laptop-lid-closed/ with no luck. Are there any other options I can try to get my computer to automatically hibernate?

EDIT: following the instructions at the above link, I've used dconf Editor to set hibernate on lid closed and also set /etc/systemd/logind.conf to hibernate on lid switch


You can easily do it.

Edit /etc/systemd/logind.conf and set

HandleLidSwitch=hibernate
HandleSuspendKey=hibernate

You can also use hybrid-sleep instead of hibernate.

Don't forget to remove the # in front of the above two lines and also to reboot.