LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   show pop-up each minute when battery is 100% charged (https://www.linuxquestions.org/questions/linux-newbie-8/show-pop-up-each-minute-when-battery-is-100-charged-4175526959/)

marchelloUA 12-01-2014 07:10 AM

show pop-up each minute when battery is 100% charged
 
Hi all,

How do I show pop-up each minute when battery is 100% charged? Maybe even with some sound...

It does show pop-up only once. I can miss it easily. I'd like to know when it is time to unplug charger in time.

How do I perform it?
Thanks ahead.

Ubuntu 14.04.1 LTS

allend 12-01-2014 08:08 AM

The battery percentage charge is likely to be found in /sys/class/power_supply/BAT0/capacity.
Popup messages can be created using 'xmessage'.
Sounds can be played using 'aplay'.
Regular checks can be scheduled using 'cron'.

i.e. Write a script that can be run as a cron job.

marchelloUA 12-01-2014 10:05 AM

Quote:

Originally Posted by allend (Post 5277529)
The battery percentage charge is likely to be found in /sys/class/power_supply/BAT0/capacity.
Popup messages can be created using 'xmessage'.
Sounds can be played using 'aplay'.
Regular checks can be scheduled using 'cron'.

i.e. Write a script that can be run as a cron job.


Tried to do it in python, can someone please comment where is my error ?

Code:

Python 3.4.0 (default, Apr 11 2014, 13:05:18)
[GCC 4.8.2] on linux
Type "copyright", "credits" or "license()" for more information.
>>> fh = open("/sys/class/power_supply/BAT0/capacity", "r")
>>> lines = [ i.rstrip() for i in fh.readlines()]
>>> print lines[2]
SyntaxError: invalid syntax
>>>


marchelloUA 12-01-2014 11:20 AM

My actual bash version:

Code:

#!/bin/sh
valuea=`cat /sys/class/power_supply/BAT0/capacity`
echo "$valuea"
if [ $valuea -eq "98" ] || [ $valuea -eq "99" ] || [ $valuea -eq "100" ] || [ $valuea -eq "97" ]
then
  echo "please unplug charger"
#  xmessage "please unplug charger"
  aplay /home/ymarkiv/Dropbox/music/wav/animals131.wav
  xmessage "please unplug charger"
else
  echo "still charging"
#  xmessage "still charging"
fi
exit
power_100.sh (END)



All times are GMT -5. The time now is 08:09 PM.