[Windows Mobile Themes] j101399j:
Finally - battery script

Well I fixed the code, the issue was that I was using "reset" as a variable. That is a MortScript command to reset the device. Once I changed that, it worked. I also simplified the if/elseif/else box to be all inclusive. Basically it acts the same as the original script but with a twist:

The code starts by creating a reg key; it then runs the code, copies the correct icon, sets the reg key value to what the current icon is and than resets iPT. When it runs the second time, it grabs the stored value from the previous run and tests it agains the current battery state. If it is the same, the icon is not copied and iPT is not reset (saving battery life and phone performance). It also kills all of the previous battery scripts that I could think of. This should run a lot smoothly and save a little more battery life. Again this code would not be possible without CU.

#batterylevelindicator by chancer63 with major changes by j101399j

##################################################################

##################################################################

#get IPT ready to be reset

RegWriteDword ("HKLM","Software\iPhoneToday","reloadIcons",0)

sleep ( 2000 )

##################################################################

##################################################################

#remove script from notification queue to make sure that you have only 1 script running

#I tried to cover all the previous script names and locations

##################################################################

##################################################################

RemoveNotifications( "\iPhoneToday\battery\mybatterylevel.mscr" )

RemoveNotifications( "\iPhoneToday\battery\thebattlevel.mscr" )

RemoveNotifications( "\iPhoneToday\battery.mscr" )

RemoveNotifications( "\iPhoneToday\mybatterylevel.mscr" )

##################################################################

##################################################################

#Test and create reg file if needed

regkey = Regread("HKLM","Software\iPhoneToday\battery","dummy")

if (regkey < 1)

RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 1)

EndIf

##################################################################

##################################################################

#set "last" to reg value

last = Regread("HKLM","Software\iPhoneToday\battery","dummy")

##################################################################

##################################################################

#Set veriables

bp = BatteryPercentage ()

extp = ExternalPowered ()

RerunIPT = 1

##################################################################

##################################################################

#test if last = current, if not change icon and refresh iPT and run again

If ((extp = 1) AND (last = 12))

RerunIPT = 3

ElseIf ((extp = 1) AND (last ne 12))

RerunIPT = 4

Copy( "\iPhoneToday\battery\icons\charging.png", "\iPhoneToday\battery\battery.png", TRUE )

RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 12)

ElseIf ((bp > 94 ) AND (last = 11))

RerunIPT = 2

ElseIf ((bp > 94 ) AND (last ne 11))

Copy( "\iPhoneToday\battery\icons\100.png", "\iPhoneToday\battery\battery.png", TRUE )

RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 11)

Elseif ((bp > 84 ) AND (last = 10))

RerunIPT = 2

Elseif ((bp > 84 ) AND (last ne 10))

Copy( "\iPhoneToday\battery\icons\90.png", "\iPhoneToday\battery\battery.png", TRUE )

RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 10)

Elseif ((bp > 74 ) AND (last = 9))

RerunIPT = 2

Elseif ((bp > 74 ) AND (last ne 9))

Copy( "\iPhoneToday\battery\icons\80.png", "\iPhoneToday\battery\battery.png", TRUE )

RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 9)

Elseif ((bp > 64 ) AND (last = 8))

RerunIPT = 2

Elseif ((bp > 64 ) AND (last ne 8))

Copy( "\iPhoneToday\battery\icons\70.png", "\iPhoneToday\battery\battery.png", TRUE )

RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 8)

Elseif ((bp > 54 ) AND (last = 7))

RerunIPT = 2

Elseif ((bp > 54 ) AND (last ne 7))

Copy( "\iPhoneToday\battery\icons\60.png", "\iPhoneToday\battery\battery.png", TRUE )

RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 7)

Elseif ((bp > 44 ) AND (last = 6))

RerunIPT = 2

Elseif ((bp > 44 ) AND (last ne 6))

Copy( "\iPhoneToday\battery\icons\50.png", "\iPhoneToday\battery\battery.png", TRUE )

RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 6)

Elseif ((bp > 34 ) AND (last = 5))
RerunIPT = 2

Elseif ((bp > 34 ) AND (last ne 5))

Copy( "\iPhoneToday\battery\icons\40.png", "\iPhoneToday\battery\battery.png", TRUE )

RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 5)

Elseif ((bp > 24 ) AND (last = 4))

RerunIPT = 2

Elseif ((bp > 24 ) AND (last ne 4))

Copy( "\iPhoneToday\battery\icons\30.png", "\iPhoneToday\battery\battery.png", TRUE )

RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 4)

Elseif ((bp > 14 ) AND (last = 3))

RerunIPT = 2

Elseif ((bp > 14 ) AND (last ne 3))

Copy( "\iPhoneToday\battery\icons\20.png", "\iPhoneToday\battery\battery.png", TRUE )

RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 3)

Elseif ((bp > 8) AND (last = 2))

RerunIPT = 2

Elseif ((bp > 8) AND (last ne 2))

Copy( "\iPhoneToday\battery\icons\10.png", "\iPhoneToday\battery\battery.png", TRUE )

RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 2)

Elseif ((bp < 8) AND (last = 1))

RerunIPT = 2

Else

Copy( "\iPhoneToday\battery\icons\00.png", "\iPhoneToday\battery\battery.png", TRUE )

RegWriteDword("HKLM","Software\iPhoneToday\battery","dummy", 1)

Endif

##################################################################

##################################################################

#find out if day or night and set reset time

GetTime ( hour, min, sec)

now = TimeStamp()

If (hour > 6 and hour < 21)

nexttime = now + (15 * 60)

Else

nexttime = now + (90 * 60)

EndIf

##################################################################

##################################################################

#Resets the reset trigger to 0; if stays 0 iPT will reset

RerunIPT = 1

##################################################################

##################################################################

#to be up- to- date when switching the phone on

RunOnPowerOn ("\iPhoneToday\battery\thebattlevel.mscr")

##################################################################

##################################################################

#iPT Reset test

if (RerunIPT = 2)

RunAt( nexttime, "\iPhoneToday\battery\thebattlevel.mscr" )

#run script at normal time and do not reset iPT

ElseIf (RerunIPT = 3)

RunAt( now + 60, "\iPhoneToday\battery\thebattlevel.mscr" )

#run script in 60 seconds and do not reset iPT

ElseIf (RerunIPT = 4)

RunAt( now + 60, "\iPhoneToday\battery\thebattlevel.mscr" )

RegWriteDword ("HKLM","Software\iPhoneToday","reloadIcons",1)

#run script in 60 seconds and reset iPT

Else

RegWriteDword ("HKLM","Software\iPhoneToday","reloadIcons",1)

RunAt( nexttime, "\iPhoneToday\battery\thebattlevel.mscr" )

#run script at normal time and reset iPT

Endif