Skip to content

Instantly share code, notes, and snippets.

@jcward
Created October 3, 2019 05:31
Show Gist options
  • Save jcward/5349d81fc62b8433610f6dbaaf2c8fcd to your computer and use it in GitHub Desktop.
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
#!/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