topic title: batti-gtk (SOLVED)
Posts: 604
thriftee
Joined: 27 Feb 2009
#16
Yes, I modified my conky a couple years ago to show the battery and go yellow, then orange, then red, and blink, but the problem is that if windows are covering it, I don't see it. I also wish it could do an audio alert when its getting really low.

Anyway, thanks for helping...
Posts: 1,062
Dave
Joined: 20 Jan 2010
#17
In your if statement for when it goes red put 'execi 60 play /path/to/audio/file' and it should play the audio file every 60 seconds as long as the battery level is low enough to be in the red.

I did this as well a while ago but with a popup window prompting me to save and shutdown or plug in the laptop.
Posts: 604
thriftee
Joined: 27 Feb 2009
#18
Well, I spent a week or two a few hours here and there with 4 books and a few hours of tutorials, thinking it would be pretty simple, and trying to learn enough python to be able to improve the app a bit and package it, but the code isn't followed easily at all, and I can't understand how to figure out what is coming from where or how it works, and couldn't find any examples of something super simple to understand how to run something in the tray (did I say that right) or where the info about the battery status is coming from, or why they didn't just look at the text on it the system puts in a file someplace (was it in /proc?, I forget at the moment, but could find it if I needed to), which was what I had expected it would be doing..

Anyway, thanks for posting and getting it working originally, Roky, and thanks for the good suggestions skidoo, but I guess its beyond my coding skills in the linux or python world to work on something I'd expect to be simple that becomes this complex..

So that brings me back to Dave's KISS solution, and I suppose if I could get it to play a sound file and popup a warning message window that would be just as good. So Dave, how did you get the message window to popup?
Posts: 765
rust collector
Joined: 27 Dec 2011
#19
here are some notification thingie information

========= SCRAPER REMOVED AN EMBEDDED LINK HERE ===========
url was:"https://wiki.archlinux.org/index.php/Desktop_notifications"
linktext was:"https://wiki.archlinux.org/index.php/De ... ifications"
====================================


I guess using notify-send, from libnotify would be ok. I am not sure if it is installed by default of not, but iIrc, the package is libnotify-bin
Posts: 1,062
Dave
Joined: 20 Jan 2010
#20
post18388.html#p18388
Posts: 604
thriftee
Joined: 27 Feb 2009
#21
Thanks for the ideas... I'm working on my conky script.

And while I worked on the script, I failed to notice that the power plug was loose, and it drained the battery and shutdown on me. I had moved the laptop to the living room, and it came loose. The screen is small, so I run the browser and editor full screen and don't see the conky.

I tried notify-send, but it doesn't work. The odd thing was that it didn't come back with an error, but didn't do anything either. I just used the simple bash script version. I'll have to read more I guess... Maybe the priority should be to find a submarine"Dive" noise to play.
Posts: 604
thriftee
Joined: 27 Feb 2009
#22
notify-send doesn't appear to work or I'm not calling it right. I used the bash example on the archwiki page. From what I could find its only used by the volumeicon and virtualbox guest, and with the volumeicon the defauly configuration doesn't use it.
Posts: 2,238
dolphin_oracle
Joined: 16 Dec 2007
#23
Notify send doesn't work in default antix. There is no notification daemon running.
Posts: 604
thriftee
Joined: 27 Feb 2009
#24
I made a bit of progress. I found that antix has notify-osd which is also used by something called unity, and there is an entry / etc/xdg/autostart/notify-osd.desktop that says to only run with certain window managers but I don't know if any of that works at all because the only one of them running is clipit, which I think I called up.

Anyway, so the exec on it is
/usr/lib/notify-osd/notify-osd

I get warning messages, but then
notify-send 'BATTERY LOW' 'Please check power' --icon=dialog-information

does pop up a message box like Manjaro sends all the time. I am thinking if I can get that running in background, and get it to send 3 nasty beeps and a critical error message popup, that should do the trick. Interesting that I didn't need to load any additional software to do this.

EDIT: I looked at Dave's conky and files.... There are nice tricks in the conky, which I will incorporate. I didn't understand the scripts, how they actually work, but it looks like they are setting up to draw a window for a message, but i don't see anything in them that tells the window to popup. I guess I don't know what is being used to make that work to be able to read up on it. The advantage being, it looks like the notify dameon wasn't needed to do it. I tested the lowbattery script and it does popup a window. I guess I need to figure out what is doing that and how to control it.
Posts: 604
thriftee
Joined: 27 Feb 2009
#25
Dave, could you point me to somewhere I can find documentation on how your lowbattery script works, please? What is that called? Its better than the other options like xmessage or whiptail, but I don't know where to look for a manual
Posts: 1,062
Dave
Joined: 20 Jan 2010
#26
There is no manual.
I will have to write what I did and what does what.
I made the little windows to prompt me instead of having a notification daemon or a power app such as xfce4-power-manager. Conky was the actual monitor that told the windows to open when the conditions were correct (battery low/ overheating).

The only downside was that the program would open a hundred times if you were not careful so I think I would want to add a condition to the windows that only allowed one instance to run for for it to be sticky as on top for the window manager
Posts: 1,062
Dave
Joined: 20 Jan 2010
#27
OK,
So updated low battery script

Code: Select all

#!/bin/bash

MESSAGE="The System Battery is Extremely low! Shut Down Now?"
TITLE="BATTERY EXTREMELY LOW!"

FLAG_FILE="/tmp/batterylow"

if [ ! -f $FLAG_FILE ]; then
    touch $FLAG_FILE
    yad --image='error' --text="$MESSAGE" #--button='ok:0' --button='cancel:1'
    case $? in
        0)    rm $FLAG_FILE && desktop-session -s    ;;
        1)    rm $FLAG_FILE && exit                  ;;
        *)    echo"Not an option" && exit                ;;
    esac
fi
And updated high temperature script

Code: Select all

#!/bin/bash

MESSAGE="The System Tempurature is Very High! Shut Down Now?"
TITLE="TEMPURATURE VERY HIGH!"

FLAG_FILE="/tmp/temphigh"

if [ ! -f $FLAG_FILE ]; then
    touch $FLAG_FILE
    yad --image='error' --text="$MESSAGE" #--button='ok:0' --button='cancel:1'
    case $? in
        0)    rm $FLAG_FILE && desktop-session -s    ;;
        1)    rm $FLAG_FILE && exit                  ;;
        *)    echo"Not an option" && exit           ;;
    esac
fi
And the part of conky to add into conky if you want the battery level to display different colors

Code: Select all

${if_existing /sys/class/power_supply/AC/online 1} ## Tells if the laptop is plugged in 
${color cccccc}Charging: ${color 4afb04}${battery_bar 10,107 BAT0}  ${color 4afb04}${battery_percent BAT0}% ##Displays battery level in bar and percent in color Green
${else}${if_match ${battery_percent BAT0} > 50} ## Runs if previous plugged in check says it is not plugged in and checks if battery level is over 50%
${color cccccc}Battery: ${color 4afb04}${battery_bar 10,107 BAT0}  ${color 4afb04}${battery_percent BAT0}% ##Displays battery level in bar and percent in color Green
${else}${if_match ${battery_percent BAT0} > 15} ## Runs if battery level is less than 50% and checks if it is over 15%
${color cccccc}Battery: ${color fc8208}${battery_bar 10,107 BAT0}  ${color fc8208}${battery_percent BAT0}% ##Displays battery level in bar and percent in color Orange
${else}${color cccccc}Battery: ${color fd0000}${battery_bar 10,107 BAT0}  ${color fd0000}${battery_percent BAT0}%${endif}${endif}${endif} ##Runs if battery level is less than 15% and displays in color red.
And the part of conky to add into conky if you want the battery level or temp level to start the scripts

Code: Select all

${if_existing /sys/class/power_supply/AC/online 0}   ## Tells if the laptop is NOT plugged in
${if_match ${battery_percent BAT0} <= 5}${execi 40 lowbattery}${endif}${endif} ## If battery level is equal to or lower than 5% display the low battery message; try every 40 seconds
${if_match ${acpitemp} >= 75}${execi 40 hightemp}${endif} ## If temperature is higher than 75 'C  display high temp message; try every 40 seconds
Place the scripts in /usr/local/bin/ and make them executable as the above conky clips are set to run the scripts as a command, where the full path is not given. If you do not want the scripts in /usr/local/bin (or on the system PATH) then give the full path the the scripts"lowbattery" and"hightemp".

Also you will need to make certain that the file
/sys/class/power_supply/AC/online
Is an actual file. For example on my current machine the file is
/sys/class/power_supply/AC0/online
and on another machine the file is
/sys/class/power_supply/AC1/online

You could also use other files for flags / system information such as
/sys/class/power_supply/BAT0/status (which displays"Charging" and"Discharging")
or
/sys/class/power_supply/BAT0/capacity (which displays the percentage level of the battery)

You will need to explore your system a little to see what might work best for you
Posts: 604
thriftee
Joined: 27 Feb 2009
#28
Bravo! I have to say, that code looks real nice and is also very understandable. Thanks for taking time to do that...

So if the message box didn't get cleared and the message is being sent again, it sees the tmp file and skips running., and on antix yad is loaded by default.

I'll see if I can get it all working for here. Thanks again.

I used your code and souped up my conky even more and , as well as having an ABC news feed, NWS weather conditions, 7 day forecast, calendar and the standard stuff, it now has displays what OS is running, as well as battery and CPU temp error popup messages and triple error beeps

Many thanks for the code and I'll leave my versions here in case anyone else needs it. It doesn't have a tray icon this way but uses almost no memory.