YOU MUST HAVE ZENYTY INSTALLED TO WORK
------------------------------------------------------------------------------------------------
Code: Select all
#!/usr/bin/perl
############################################################
### Script for allerting when battery is low on LXDE eeepc
### Author: Luca Cuzzolin
### Opensourse
############################################################
## Subroutines
# To find if is charging or not
sub plug_status {
$plug = `cat /proc/acpi/battery/BAT*/state | grep 'charging state'`;
@string_plug = split(/\s+/, $plug);
$charging_state = $string_plug[2];
}
# To find remaining capacity
sub battery_status {
$remaining_capacity = `cat /proc/acpi/battery/BAT*/state | grep 'remaining capacity'`;
@string_rcapacity = split(/\s+/, $remaining_capacity);
$mAh = $string_rcapacity[2];
}
# Battery warning popup with zenity (will be inplemented with gtk in future)
sub battery_warning {
$warning = `zenity --warning --text="Batteria Scarica" & aplay /usr/share/sounds/system_sounds/Drip.wav`;
$numb = 10;
while($numb--){
sleep(1);
}
my $command = `killall eeepc_battery_alarm.pl & eeepc_battery_alarm.pl`;
}
# Loop if acplug is unplugged and remaining capacity is = or less than $mAh do warning else redo the loop (sub else_mAh)
sub if_mAh {
if ($mAh <= 10 and $charging_state =~ m/discharging/ ) {
&battery_warning;
}
else {
&else_mAh;
}
}
# else redo the loop
sub else_mAh {
$num = 10;
while($num--){
sleep(1);
}
&plug_status;
&battery_status;
&if_mAh;
}
### Main program
&plug_status;
&battery_status;
&if_mAh;
### End
----------------------------------------------------------------------------------------------------------------
make a file as root with vi or nano or others in /usr/bin/ and name it eeepc_battery_alarm.pl
sudo vi /usr/bin/eeepc_battery_alarm.pl
copy the script inside the file
exit vi or other editors.
change permission to the file eeepc_battery_alarm.pl
chmod 755 /usr/bin/eeepc_battery_alarm.pl
if you want to adgiust your alert left time, open the file eepc_battery_alarm.pl and change $mAh <= 10 to $mAh <= any_multiple_of_10_taht_you_want
then in if you want to start in automatic on login user just make a .desktop file in /home/USER/.config/autostart/
vi /home/YOUR_USER/.config/autostart/eeepc_battery_alarm.desktop
and write this in to it:
[Desktop Entry]
Type=Application
Exec=eeepc_battery_alarm.pl
exit vi or other editors
first time you can run it just tiping in the terminal
eeepc_battery_alarm.pl
The script is very spartan but those it do what i want. I did not implement plug/unplug alarm but it is very easy to do if you want.
i used zenity but you can implement the script using gtk.
enjoy