Friday, April 26, 2024
7
rated 0 times [  7] [ 0]  / answers: 1 / hits: 8254  / 2 Years ago, sun, july 17, 2022, 9:37:26

Sometimes my charger remains plugged into laptop even after charging is complete.



Is there a way to get a pop-up message/notification when my battery gets full due to charging or is there any software/package which can provide the functionality?


More From » software-recommendation

 Answers
4

Install the acpi package. Now put this in return0whencharging.sh and make it executable:



#!/bin/sh
acpi -V
if cat /proc/acpi/battery/BAT1/state | grep "charging state" | grep -vE ":[ ]*charging$"; then
exit 1
else
exit 0
fi


If echo -e "a" makes a sound, start this when you want to watch the battery status:



watch --beep return0whencharging.sh


If it doesn't make any sound or you want a notification and a better alarm than whatever watch can provide, install libnotify-bin and mpv and use this instead:



while return0whencharging.sh; do sleep 1; done; notify-send "Finished charging" && mpv -loop /usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga


Explanation:



If you look at the man page for grep you can see that -v reverses the matching, and therefore the return/status code. -E means it's a regular expression. the [ ] in the regex (regular expression) means "tab or space". The following star makes it mean "tab or space 0 or more times". The trailing "$" means that it should match the end of the line. The final grep means that lines NOT ending in a ":", any number of tabs or spaces and then "charging" and the end of the line should make grep exit with status code 0. This means that grep will return 1 as long as the computer is charging. The if will execute it's first branch when the status code is 0, which means we are effectively negating the result of grep, since we exit 1 when grep exits 0 and exit 0 when grep exists non-zero.


[#36453] Tuesday, July 19, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
biryanrownies

Total Points: 396
Total Questions: 90
Total Answers: 106

Location: Saint Lucia
Member since Sun, Sep 5, 2021
3 Years ago
biryanrownies questions
Wed, Sep 7, 22, 18:13, 2 Years ago
Fri, Dec 3, 21, 02:50, 2 Years ago
Sat, Feb 12, 22, 16:02, 2 Years ago
Sat, Apr 15, 23, 09:22, 1 Year ago
;