1

I'd like a debian laptop with LXDE to do a system beep every 10 or 30 seconds once the battery reaches a critical level. is that possible?

1 Answer 1

2

Yes, it is possible. One way is listening for udev events when the battery level changes, and comparing it against a threshold. Otherwise, this is a quick and dirty way. Make a systemd service to start this in the background at boot and you'll get beeps every 10 seconds once your battery level drops below 5%.

#!/bin/bash

let CRIT_BATT_LVL=5
let PERIOD=10

exec 3>&2
exec 2>/dev/null

while true; do
  level=$(acpi -b | grep -oP '\d+(?=%)')
  if [ $level -lt $CRIT_BATT_LVL ]; then
    timeout -k 0.75s 0.5s speaker-test --frequency 2000 --test sine >/dev/null
  fi
  sleep $PERIOD
done

exec 2>&3
exec 3>&-

The beeps will sound through your speakers. Make sure they aren't muted. If you want a beep through a motherboard speaker, look into the beep utility.

2
  • 1
    Also you need to check the charging status if acpi -b | grep Discharging; then ... , to stop beeping while charging.
    – GAD3R
    Mar 10, 2020 at 15:03
  • Generalized this and systemd/udev rules into a gist
    – Akom
    May 5, 2021 at 15:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .