Results 1 to 6 of 6

Thread: show pop-up each minute when battery is 100% charged

  1. #1
    Join Date
    Jul 2014
    Beans
    340

    Question 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.

    Lubuntu 14.04.1 LTS


    Upd:

    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'.

    Could someone please help to write a script that can be run as a cron job?
    Last edited by marchello_lippi2; December 1st, 2014 at 03:34 PM.

  2. #2
    Join Date
    Jul 2014
    Beans
    340

    Re: show pop-up each minute when battery is 100% charged

    Tried to do it in python, can someone please comment where is my error ?
    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
    >>>

  3. #3
    Join Date
    Jul 2014
    Beans
    340

    Re: show pop-up each minute when battery is 100% charged

    My bash version for this moment...

    #!/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/user1/test.wav
    xmessage "please unplug charger"
    else
    echo "still charging"
    # xmessage "still charging"
    fi
    exit
    power_100.sh (END)
    Last edited by marchello_lippi2; December 1st, 2014 at 06:26 PM.

  4. #4
    Join Date
    Oct 2007
    Beans
    1,832

    Re: show pop-up each minute when battery is 100% charged


  5. #5
    Join Date
    Nov 2011
    Beans
    2,336
    Distro
    Ubuntu

    Re: show pop-up each minute when battery is 100% charged

    Do you really need to run a once-per-minute cron job to pop up a notice every minute, or is the goal just to have something pop up when the battery is 100% charged *and stay on the screen* until you notice it?

  6. #6
    Join Date
    Jul 2014
    Beans
    340

    Re: show pop-up each minute when battery is 100% charged

    This is my actual bash version. It is like resident program. It is started at lubuntu desktop boot and reside in memory. Well, I will test it during few days, but now it looks just fine.

    #!/bin/sh

    DELAY=60
    while sleep $DELAY
    do
    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"
    aplay /home/user1/test.wav
    if ! xmessage -nearmouse -buttons continue:0,stop:1 "please unplug charger"
    then
    exit 0
    fi
    else
    echo "still charging"
    # xmessage "still charging"
    fi
    done

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •