Created
October 3, 2019 05:31
-
-
Save jcward/5349d81fc62b8433610f6dbaaf2c8fcd to your computer and use it in GitHub Desktop.
Quick script to check the laptop lid state (Surface Pro 3, Ubuntu 18.04), and trigger hibernate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Disable lid control in /etc/systemd/logind.conf, for example: | |
# | |
# [Login] | |
# HandlePowerKey=hibernate | |
# HandleSuspendKey=ignore | |
# HandleLidSwitch=ignore | |
cnt = 0 | |
while true | |
val = `cat /proc/acpi/button/lid/LID0/state` | |
if (val.include?("closed")) then | |
puts " - closed!" | |
cnt = cnt + 1 | |
if (cnt > 5) then | |
cnt = 0 | |
puts "LID triggered hibernate!" | |
`systemctl hibernate` | |
`sleep 30` | |
end | |
else | |
puts " - NOT closed!" | |
cnt = 0 | |
end | |
`sleep 5` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment