voila un script qui permet d'afficher l'état de la batterie de votre portable dont voici les caractéristiques :
- En cliquant on peut afficher soit le pourcentage soit le nombre de minutes restantes.
- Une petite icone indique les différents états.
- Un son est joué lorsque la batterie est presque vide.
Bon ce script n'est loin d'etre parfait, on peut dire que ça "marchouille"... mais au moins cémoikiléfé !!

Donc soyez indulgent, et surtout aidez moi à l'améliorer si vous voyez des choses qui ne vont pas.
Voici le script :
Code : Tout sélectionner
WindowTitle {FvwmScript-AcpiBatt}
WindowSize 76 24
Font "xft:Tahoma:pixelsize=12:Bold"
Colorset 1
########## BEGINING THE INITIALISATION ################
Init
Begin
Set $battPresent = (GetOutput {cat /proc/acpi/battery/BAT?/info} 1 2)
Set $display = hour
########## IF BATTERY IS PRESENT ############
If $battPresent==yes Then
Begin
Set $last_prev = (GetOutput {cat /proc/acpi/battery/BAT?/info} 3 4)
Set $last = $last_prev
Set $remaining = (GetOutput {cat /proc/acpi/battery/BAT?/state} 5 3)
Set $acstate = (GetOutput {cat /proc/acpi/ac_adapter/AC*/state} 1 2)
Set $batt = (Mult 100 $remaining)
Set $batt = (Div $batt $last)
Set $batt = $batt %
Set $temps = 0 h 55
Set $alert = 0
Set $batt_prev = -1
Set $counthour = 0
Set $IconBatt = {22x22/status/battery-100.png}
Set $IconBatt2 = {22x22/status/battery-charging.png}
####### IF THE LAPTOP USE THE BATTERY ########
If $acstate==off-line Then
Begin
Set $alert = 0
#Do {Exec echo "powersave" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor}
####### SWITCH THE DISPLAY BETWEEN PERCENT OR TIME #############
If $display=={percent} Then
Begin
Set $batt = * $batt
ChangeTitle 1 $batt
ChangeIcon 2 $IconBatt
End
Else
Begin
Set $temps = * $temps
ChangeTitle 1 $temps
ChangeIcon 2 $IconBatt
End
End
######## IF THE LAPTOP USE THE AC POWER #########
Else
Begin
Set $alert = 0
#Do {Exec echo "performance" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor}
######### SWITCH THE DISPLAY BETWEEN PERCENT OR TIME ##########
If $display=={percent} Then
Begin
ChangeTitle 1 $batt
ChangeIcon 2 $IconBatt
End
Else
Begin
ChangeTitle 1 $temps
ChangeIcon 2 $IconBatt2
End
End
End
######### IF BATTERY IS NOT PRESENT #############
Else
Begin
Set $IconBatt = {22x22/status/battery-missing.png}
Set $temps = NoTime
Set $batt = NoBatt
############## SWITCH THE DISPLAY BETWEEN PERCENT OR TIME ###############
If $display=={percent} Then
Begin
ChangeTitle 1 $batt
ChangeIcon 2 $IconBatt
End
Else
Begin
ChangeTitle 1 $temps
ChangeIcon 2 $IconBatt
End
End
End
##### END OF INITIALISATION ################
####################################
######################################
########## IF BATTERY IS PRESENT ############
PeriodicTasks
Begin
If (RemainderOfDiv (GetTime) 60)==0 Then
Begin
Set $battPresent = (GetOutput {cat /proc/acpi/battery/BAT?/info} 1 2)
Set $display = hour
#If $batt==$batt_prev Then
# Begin
# # do nothing
# End
If $battPresent==no Then
Begin
Set $IconBatt = {22x22/status/battery-missing.png}
Set $batt = NoBatt
Set $temps = NoTime
############## SWITCH THE DISPLAY BETWEEN PERCENT OR TIME ###############
If $display=={percent} Then
Begin
ChangeTitle 1 $batt
ChangeIcon 2 $IconBatt
End
Else
Begin
ChangeTitle 1 $temps
ChangeIcon 2 $IconBatt
End
End
Else
Begin
Set $last_prev = (GetOutput {cat /proc/acpi/battery/BAT?/info} 3 4)
Set $remaining_batt = (GetOutput {cat /proc/acpi/battery/BAT?/state} 5 3)
Set $batt = (Mult 100 $remaining_batt)
Set $batt = (Div $batt $last_prev)
Set $batt_prev = $batt
Set $acstate = (GetOutput {cat /proc/acpi/ac_adapter/AC*/state} 1 2)
Set $IconBatt = {22x22/status/battery-100.png}
Set $IconBatt2 = {22x22/status/battery-charging.png}
If $batt>99 Then
Begin
Set $IconBatt = {22x22/status/battery-100.png}
Set $IconBatt2 = {22x22/status/battery-charging.png}
ChangeColorset 1 1
End
Else
Begin
If $batt>74 Then
Begin
Set $IconBatt = {22x22/status/battery-080.png}
Set $IconBatt2 = {22x22/status/battery-charging-080.png}
End
Else
Begin
If $batt>49 Then
Begin
Set $IconBatt = {22x22/status/battery-060.png}
Set $IconBatt2 = {22x22/status/battery-charging-060.png}
End
Else
Begin
If $batt>24 Then
Begin
Set $IconBatt = {22x22/status/battery-040.png}
Set $IconBatt2 = {22x22/status/battery-charging-040.png}
End
Else
Begin
If $batt>12 Then
Begin
Set $IconBatt = {22x22/status/battery-caution.png}
Set $IconBatt2 = {22x22/status/battery-charging-caution.png}
End
Else
Begin
Set $alert = (Add $alert 1)
If $alert==1 Then
Begin
Do{ Exec aplay $[SOUNDS_PATH]/AlertBatt.wav}
Set $IconBatt = {22x22/status/battery-low.png}
Set $IconBatt2 = {22x22/status/battery-charging-low.png}
ChangeForeColor 1 {#FF0000}
ChangeForeColor 2 {#FF0000}
End
Else
Begin
Set $IconBatt = {22x22/status/battery-low.png}
Set $IconBatt2 = {22x22/status/battery-charging-low.png}
ChangeForeColor 1 {#FF0000}
ChangeForeColor 2 {#FF0000}
End
If $batt<5 Then
Do{ Exec aplay $[SOUNDS_PATH]/AlertLowBatt.wav }
End
End
End
End
End
Set $batt = $batt %
############################ BATT DISCHARGING ###############
If $acstate==off-line Then
Begin
Set $remaining_prev = $remaining
Set $remaining = (GetOutput {cat /proc/acpi/battery/BAT?/state} 5 3)
Set $koko = (Mult $remaining -1)
Set $ecart = (Add $remaining_prev $koko)
If $ecart==0 Then
Begin
Set $ecart = 9
End
Else
Begin
#Do nothing
End
Set $temps = (Mult 60 $remaining)
Set $temps = (Div $temps $ecart)
Set $tempshour = (Div $temps 60)
Set $tempsminute = (RemainderOfDiv $tempshour 60)
Set $tempshour = (Div $tempshour 60)
If $tempsminute<10 Then
Begin
Set $tempsminute = 0 $tempsminute
End
Set $temps = $tempshour h $tempsminute
If $display=={percent} Then
Begin
Set $batt = * $batt
ChangeTitle 1 $batt
ChangeIcon 2 $IconBatt
End
Else
Begin
Set $temps = * $temps
ChangeTitle 1 $temps
ChangeIcon 2 $IconBatt
End
End
###################### AC ON - Charging ##################
Else
Begin
Set $remaining_prev = $remaining
Set $remaining = (GetOutput {cat /proc/acpi/battery/BAT?/state} 5 3)
Set $koko = (Mult $remaining_prev -1)
Set $ecart = (Add $remaining $koko)
If $ecart==0 Then
Set $temps = {OK}
Else
Begin
Set $temps = (Mult 60 $remaining)
Set $temps = (Div $temps $ecart)
Set $tempshour = (Div $temps 60)
Set $tempsminute = (RemainderOfDiv $tempshour 60)
Set $tempshour = (Div $tempshour 60)
If $tempsminute<10 Then
Begin
Set $tempsminute = 0 $tempsminute
End
Set $temps = $tempshour h $tempsminute
End
If $display=={percent} Then
Begin
ChangeTitle 1 $batt
ChangeIcon 2 $IconBatt2
End
Else
Begin
ChangeTitle 1 $temps
ChangeIcon 2 $IconBatt2
End
End
End
End
End
#widget to display the text
Widget 1
Property
Position 22 0
Size 55 24
Type ItemDraw
Flags NoReliefString
Title {}
Colorset 1
Main
Case message of
SingleClic :
Begin
# switch between percent and time view
If $display=={percent} Then
Begin
Set $display= hour
ChangeTitle 1 $batt
End
Else
Begin
Set $display= percent
ChangeTitle 1 $temps
End
End
End
# widget to display the battery icons
Widget 2
Property
Position 2 0
Size 18 22
Type ItemDraw
Icon {}
Flags NoReliefString
Main
Case message of
SingleClic :
Begin
End
End
Code : Tout sélectionner
# AcpiBatt {{{1
All (FvwmButtons-AcpiBatt) Close
DestroyModuleConfig FvwmButtons-AcpiBatt: *
*FvwmButtons-AcpiBatt: Geometry 76x24-56+1
*FvwmButtons-AcpiBatt: BoxSize smart
*FvwmButtons-AcpiBatt: ActiveColorset $[cs_panel_active]
*FvwmButtons-AcpiBatt: Colorset $[cs_panel_inactive]
*FvwmButtons-AcpiBatt: Columns 2
*FvwmButtons-AcpiBatt: Padding 2 2
*FvwmButtons-AcpiBatt: Frame 0
*FvwmButtons-AcpiBatt: (2x1, Size 76 25, Swallow (Close, Respawn) "FvwmScript-AcpiBatt2")
Module FvwmButtons FvwmButtons-AcpiBatt
Script components/scripts/FvwmScript-AcpiBatt2
http://mysthr.free.fr/Documents/icon-batt.tar
Que je met dans le dossier $[Ou sont vos icone]/22x22/status/
Et pour les sons :
http://mysthr.free.fr/Documents/sons-batt.tar
Sinon j'ai un fichier de config avec mes variables d'environnement pour les sons et les icones :
SetEnv ICON_PATH $[FVWM_USERDIR]/icons
SetEnv SOUNDS_PATH $[FVWM_USERDIR]/sounds
Voila j'espère que quelqu'un pourra m'aider a améliorer ce script qui par moment se grise lorsque l'on clique trop dessus ... :p
Edit : Ha oui j'avais oublié de précisé, par rapport à l'exemple d'utilisation de ce script, que sur ma config, mon script s'appel FvwmScript-AcpiBatt2 ... donc à adapter au votre.