Background (can be skipped): Because of some (probably hardware) defect, my laptop sometimes disconnects from the battery without warning, causing an immediate and insecure shutdown if the AC adapter is not attached to computer and power supply. Several so-called computer repairers have proven completely unable to locate the problem (one tried to make me change my harddrive, claiming that 80% of it was corrupted even though I could still access all my files) so after having wasted a lot of money and getting nothing, I decided to just live with it and only use the laptop when it's connected to an external power supply.
Actual question: How can I make Ubuntu (16.04) immediately notify me (by text message and/or sound) whenever the power supply through the AC adapter is interrupted?
Own attempt: I wrote the following script
notify-send -i face-worried "No power!" "Connect the adapter."
which can be run from /opt/custom_scripts/warning_AC.sh
both as root and as user (I tried both in bash
). I have then tried to mimic the method explained in this answer on unix SA to let this script be run whenever the AC chord is plugged in. That is, I have monitored
sudo udevadm info --path=/sys/class/power_supply/AC0
to identify the changes made when plugging adapter in or out. I saw (among others)
E: POWER_SUPPLY_NAME=AC0
E: POWER_SUPPLY_ONLINE=0
E: SUBSYSTEM=power_supply
where in the second line the 0
changed to 1
when the power chord was plugged in and vice versa when it was plugged out. I thus decided the script I needed to place in /etc/udev/rules.d/80-power.rules
was
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_NAME}=="AC0", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/opt/custom_scripts/warning_AC.sh"
I rebooted the computer, but nothing happened when plugging the power in or out.
I am very new to Linux and Ubuntu and willing to learn as much as I can about commands and scripts and stuff but this is as far as I got. Thanks for your help.
From OmgUbuntu, the app that perfectly fits your definition,
BATTERY MONITOR
.First install the dependencies:
Then, install via ppa:
OR
Download the app from the developer's Github page and install it (considering you are using
Xenial
):Though not mentioned but it doesn't hurt to do a quick restart.
EDIT:- Also, it seems you need to manually launch the app atleast once for the app to start working.