Different battery monitor needed -- Trisquel 8, MATE

3 risposte [Ultimo contenuto]
anatom

I am a member!

Offline
Iscritto: 09/20/2012

I've just recently replaced and upgraded my battery. I'd like to try some advice I found, namely to keep your Li-ion battery always withing 10--90% in order to make it last longer. Now I'm a little annoyed that there seems to be no energy settings option in order that a message and a distinctive sound signal appears when either of these values are reached. This would help me to unplug or plug in, respectively. I'm sure there is a solution that my GNU/Linux ignorance made me not find, so I'm hoping for advice.
Thanks in advance!

Magic Banana

I am a member!

Offline
Iscritto: 07/24/2010

That small shell script should do what you want (you can change PERIOD, which is the number of seconds between two checks, the thresholds, the messages and the sound file):

#!/bin/sh
LOW=10
HIGH=90
PERIOD=10
old=$(cat /sys/class/power_supply/BAT0/capacity)
while sleep $PERIOD
do
new=$(cat /sys/class/power_supply/BAT0/capacity)
if [ $old -gt $LOW -a $old -lt $HIGH ]
then
if [ $new -le $LOW ]
then
notify-send "Low battery: $new%"
aplay /usr/share/sounds/question.wav
elif [ $new -ge $HIGH ]
then
notify-send "High battery: $new%"
aplay /usr/share/sounds/question.wav
fi
fi
old=$new
done

Copy the code in a file. Turn that file executable, for instance by clicking the box "Allow executing file as program" in the "Permissions" tab of the "Properties" you can access from a right click on the file. Finally, in the "Startup Applications", in MATE's "Control Center", you can "Add" the script: click on the "Browse..." button and select the file. You will have to log out and to log in again to see if that works.

anatom

I am a member!

Offline
Iscritto: 09/20/2012

Thank you very much! This script has been playing reliably a sound at 20%/80% for a couple of weeks now. How can I configure which sound is played? And can I also make a notification appear? Thanks in advance.

anatom

Magic Banana

I am a member!

Offline
Iscritto: 07/24/2010

I hard-coded everything in the script. That includes the played sound, /usr/share/sounds/question.wav, and how to play it, with aplay, which can only play raw formats. You can modify both lines "aplay /usr/share/sounds/question.wav" (and even play a different sounds, depending on whether the battery became low or high). For example, to play the far more noticeable /usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga file with paplay (which can play that file format and more):
paplay /usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga

We can change the script so that the file(s) to play, the two thresholds, the check period, ... become arguments. Since you will not run the command by hand, it does not look very useful to do so, in my opinion.

notify-send (on the two previous lines) is supposed to send a notification. It works on GNOME Shell. I am surprised it does not work on MATE. Try to execute the following command in a terminal emulator:
$ notify-send banana
Is "banana" displayed in a notification? If not, any error message?