Battmon

Battmon is a simple acpi battery monitor applet that sits in the system tray. It is written in bash/zenity and has support for hibernation when the battery reaches a critical level (5%).

battmon system tray applet

Download the source tarball here. Current version 0.9.1.

REQUIREMENTS:
bash
gtk+2.0 version 2.20 or later
zenity version 2.30 or later
acpi installed and enabled
pm-utils and specifically pm-hibernate

INSTALLATION:

tar -zxvf battmon-0.9.1.gz
cd battmon-0.9.1
./configure
su (or sudo)
[type root password and hit enter]
./install

The executable is installed to /usr/local/bin and resource files to /usr/local/share/battmon). The executable is called, “battmon”.

USAGE:
Run “battmon” (without the quotes) to start the applet.
Add “battmon &” (without the quotes) to your window manager startup file
Type battmon -u for command line options:

-s to set the sleep delay in seconds-b to set a beep on critical battery (-b 1 = on, -b 0 = off)
-h to hibernate on critical battery (-h 1 = on, -h 0 = off) (requires pm-utils to be installed)
-d to specify an alternate path for tray icons to allow for user customization
-f to print all icon file names to help with customization
-u to print usage options
-q to stop the applet

Defaults are a 10 second sleep delay between updates and no beep or hibernate.

UNINSTALL:
su to root or sudo    ./uninstall

AUTHOR:
richjack with additions from Gareth Edwards

CONTACT:
richjack80 at yahoo dot com
Leave comments below in the absence of a proper bug tracker.

LICENSE:
Battmon is licensed under the GPLv2.
Icons are licensed under the GPLv2 and are adapted from KDE4 Oxygen icons using GIMP.

10 Responses to Battmon

  1. mdawkins says:

    I just imported this pkg into the repos. Please let me know if it works right.
    I added a desktop file and reused the 90-100 charged icon for it.

    The only thing I noticed is that you cannot right click to kill the app if you don’t want it, but very nice.

    Good job guys.

    Matt

    • chameleonos says:

      Wow, that was quick, thanks mdawkins. I’ll try installing it from the repos and let you know how it goes.

      Zenity doesn’t have a right-click function on the system tray icon, so I added a command line parameter: battmon -q will kill the running instance!

      • chameleonos says:

        mdawkins – just tested battmon from the Unity repos – installed just fine and works like a treat. Thanks so much 😉

        I have received some feedback from the Crunchbang forums so I will need to tweak it slightly. When I do I’ll let you know so you can update the RPM. I am also very much thinking about rewriting it in Python as I am a lot more comfortable with Python and GTK than I was when I started this project. However, that will have to wait until I have finished the next ChameleonOS release!

  2. landeel says:

    Wow, just wanted to say thank you so much for this tool.
    I’m using LXDE here, but its battery monitor doesn’t work.
    battmon is the perfect replacement.
    THANK YOU!

  3. thraspic says:

    I checked for all the pre-reqs, followed the instructions exactly, and when I try running battmon (battmon -u) I get:

    bash: /usr/local/bin/battmon: Permission denied

    I then tried sudo battmon, and I get ‘command not found’. I’ve tried this a few times now, always with the same result.

  4. thraspic says:

    Haha… sad. I just had to adjust the properties “Make this file executable”, as root, and there we go. You may want to consider adding that to the instructions.

  5. princethrash says:

    Is Battmon still compatible with the new zenity?

    I’m getting this error message:

    WARNING **: Error showing notification: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.Notifications was not provided by any .service files

    Is this problem related to this?:

    https://bugs.archlinux.org/task/23720

      • fuzebest says:

        Ok. I got totally sick of this new zenity “tricks”.
        I replaced zenity with yad (http://code.google.com/p/yad/) and notify-send (from libnotify-bin).
        And middle mouse button exit works now…
        Please find the patch attached.

        — battmon 2010-09-01 05:38:39.000000000 +1000
        +++ battmon.new 2012-01-07 11:35:57.717596692 +1100
        @@ -2,7 +2,7 @@

        # battmon version 0.9.1
        #
        -# Simple zenity notification script that uses acpi to check battery status
        +# Simple yad notification script that uses acpi to check battery status
        # Uses icons adapted from KDE4 Oxygen icons, but users can specify their own icon directory
        # as long as icon names match those in the script
        # Just add [pathto/battmon &] to your openbox autostart.sh file and it will sit in the system tray
        @@ -27,19 +27,7 @@
        # along with Systray Battery Monitor. If not, see
        # .
        #
        -# Quit function
        -function quit_monitoring(){
        -ZENPIDA=$(cat $TMP/zenpid.tmp | awk ‘{print $1}’)
        -ZENPIDB=$(cat $TMP/zenpid.tmp | awk ‘{print $2}’)
        -rm -f $TMP/zenpid.tmp
        -kill -9 $ZENPIDA > /dev/null 2>&1 &
        -wait;
        -kill -9 $ZENPID2 > /dev/null 2>&1 &
        -wait;
        -killall battmon > /dev/null 2>&1 &
        -wait;
        -exit 0
        -}
        +
        ################### USER INTERACTION ######################
        #
        # Default icon path and delay between tooltip updates
        @@ -57,7 +45,6 @@
        h) HIB=”$OPTARG”;;
        f) ls “/usr/local/share/battmon/icons” | sed ‘s/[*]//’ # print icon filenames and exit
        exit 0;;
        – q) quit_monitoring;; # kill script and all zenity instances associated with it
        u|\?) # unknown flag
        echo >&2 \

        @@ -75,7 +62,6 @@
        [uses pm-hibernate so you need pm-utils installed]
        for on -h 1 or -h 0 for off (default)
        -f print icon filenames and exit
        – -q quit, stop monitoring, kill tray icon, go away…
        -u print these usage instructions and exit

        DEFAULTS:
        @@ -133,7 +119,7 @@
        }

        ########################### Main functions ######################################
        -# Create system tray icon using zenity
        +# Create system tray icon using yad
        function systray(){
        # Gathers information on current battery status
        PLUGGED=$(acpi -a | awk -F “: ” ‘{print $2}’)
        @@ -146,7 +132,7 @@
        echo “icon:$ICON_DIR/$ICON_MISS” >&3
        echo “tooltip:Battery not found” >&3
        while [ $m -le 1 ]; do
        – echo “message:Battery missing or taken out – check battery is inserted correctly.” >&3
        + $(notify-send -i $ICON_DIR/$ICON_MISS “Battery is missing” “Battery missing or taken out – check battery is inserted correctly.”)
        let m=m+1
        done
        elif [ $CHARGE -ge 90 ]; then
        @@ -216,7 +202,7 @@
        ;;
        (*) # Highly unlikely to ever occur, but you never know!
        echo “icon:$ICON_DIR/$ICON_ERR” >&3
        – echo “message:Battery error – unknown error, exiting in 10 seconds…” >&3
        + $(notify-send -i $ICON_DIR/$ICON_ERR “Battery error” “Battery error – unknown error, exiting in 10 seconds…”)
        echo “tooltip:Battery error” >&3
        sleep 10
        exit 1
        @@ -224,17 +210,17 @@
        esac
        }

        -# Warning messages via tray baloon dialog at 20, 15 and 10% remaining
        +# Warning messages via tray baloon dialog at 30, 25 and 10% remaining
        function warning_le20(){
        -echo “message:Warning, battery charge has only ${CHARGE}% remaining.” >&3
        +$(notify-send -i $ICON_DIR/$ICON_D10_19 “Battery charge is low” “Warning, battery charge has only ${CHARGE}% remaining.”)
        let i=i+1
        }
        function warning_le15(){
        -echo “message:Warning, battery charge has only ${CHARGE}% remaining.” >&3
        +$(notify-send -i $ICON_DIR/$ICON_D10_19 “Battery charge is low” “Warning, battery charge has only ${CHARGE}% remaining.”)
        let j=j+1
        }
        function warning_le10(){
        -echo “message:Warning, battery charge has only ${CHARGE}% remaining.” >&3
        +$(notify-send -i $ICON_DIR/$ICON_D6_9 “Battery charge is low” “Warning, battery charge has only ${CHARGE}% remaining.”)
        let k=k+1
        }

        @@ -244,10 +230,10 @@
        echo -en “\x07”
        fi
        if [ $HIB = 0 ]; then
        – echo “message:Warning, battery charge has only ${CHARGE}% remaining.\nSwitch to mains power immediately or save all work now!\nComputer will loose power imminently…” >&3
        + $(notify-send -i $ICON_DIR/$ICON_D0_5 “Battery charge is critical” “Warning, battery charge has only ${CHARGE}% remaining.\nSwitch to mains power immediately or save all work now!\nComputer will loose power imminently…”)
        elif [ $HIB = 1 ]; then
        while [ $X -ge 1 ]; do
        – echo “message:Warning, battery charge has only ${CHARGE}% remaining.\nSwitch to mains power immediately or save all work now!\nComputer will hibernate in $X seconds…” >&3
        + $(notify-send -i $ICON_DIR/$ICON_D0_5 “Battery charge is critical” “Warning, battery charge has only ${CHARGE}% remaining.\nSwitch to mains power immediately or save all work now!\nComputer will hibernate in $X seconds…”)
        PLUGGED2=$(acpi -a | awk -F “: ” ‘{print $2}’)
        if [[ “$PLUGGED2” == “on-line” ]]; then
        break
        @@ -261,7 +247,7 @@
        systray
        index
        elif [[ “$PLUGGED2” == “off-line” ]]; then
        – echo “message:Preparing to hibernate computer…” >&3
        + $(notify-send -i $ICON_DIR/$ICON_D0_5 “Battery charge is critical” “Preparing to hibernate computer…”)
        pm-hibernate
        fi
        fi
        @@ -319,23 +305,17 @@

        ########################### Start the applet ######################################

        -# Start up a zenity notification system tray icon with a randomly generated title ID
        +# Start up a yad notification system tray icon with a randomly generated title ID
        ID=$RANDOM
        -exec 3> >(zenity –notification –title “$ID” –listen)
        +exec 3> >(yad –kill-parent –notification –title “$ID” –listen)
        # Now select the correct icon and tooltip
        index
        systray

        -# Get pid numbers of this zenity and export them to a file so they can be killed by the user
        -ZENPID1=$(ps axf | grep “zenity –notification –title “$ID” –listen” | awk ‘{print $1}’ | sed q )
        -ZENPID2=$(ps axf | grep “zenity –notification –title “$ID” –listen” | awk ‘{print $1}’ | sed ‘$!d’ )
        -rm -f $TMP/zenpid.tmp
        -echo “$ZENPID1 $ZENPID2” >> $TMP/zenpid.tmp

        -# The main loop to ensure that the zenity icon doesn’t disappear
        +# The main loop to ensure that the yad icon doesn’t disappear
        # and to check if the user has plugged in or unplugged the AC adapter
        while true; do
        monitoring
        sleep $DELAY
        PLUGGED=$(acpi -a | awk -F “: ” ‘{print $2}’)
        -done
        \ No newline at end of file
        +done

  6. Pingback: Fix Gdbus Error Freedesktop Windows XP, Vista, 7, 8 [Solved]

Leave a comment