[Windows Mobile Software Development] Deleted member 1890170:
Hello all, first post here.

I've been working with Mortscript for a while now and I'm very happy with it.

Here's my attempt at a 3-script-pack. It should toggle my PND on/off in accordance to given AC power supply. But it doesn't work as expected,

especially the RunAt() seems not to work: only one event (the notify set in script ON_AC_POWER_LOSS) is executed by the scheduler, the notify set

in script ON_AC_POWER_DAEMON obviously is never executed by the scheduler. Anyone an idea?

# ON_AC_POWER_LOSS.mscr
#
# jwoegerbauer 09/04/2009
# GNU General Public License (GPL), Version 2, June 1991
#
#
# NO ERROR CHECKING IS DONE !!!
#
#ErrorLevel("off")
#
# Before using this script ensure file PowerNotifyFlags.ini
# is present and contains the following lines:
#
# [PowerOnOff]
# ACPower=1/0
#
#
Local()
#
#
# check for sufficient power or don't run anything and don't resubmit
If (BatteryPercentage() <= 35)
SleepMessage(5, "Battery level is low: " & BatteryPercentage(), "Power Warning", 1))
Exit
EndIf
#
# adjust to your needs
Set WAIT_SECS, 0
Set CHECK_BACK_SECS, 30 #must be equal or greater 10
Set PLAY_SOUND, 1
Set WAV_FILE, "\My Flash Disk\programme\TroNikPowerNotifier\chime_down.wav"
Set REG_POWER_HIVE, "HKLM"
Set REG_POWER_PATH, \
"System\CurrentControlSet\Control\Power"
Set INI, \
"\My Flash Disk\programme\TroNikPowerNotifier\PowerNotifyFlags.ini"
Set INI_SECTION, "PowerOnOff"
Set INI_KEY, "ACPower"
Sleep 100
#
# assume the device is running on external power and we unplug
# the usb-powered cable or engined off, and the power is re-supplied
# we should Cancel this script automatically.
# IMO this is a useful case when we use the device in the car in
# ignition mode and then start the engine.
#
# hence we implement now an additional power state listener (a sec timer)
While(%WAIT_SECS% > 0)
#
# yield 1 second
Sleep 1000
#
# query current power state
acPower = ExternalPowered()
If (acPower = TRUE )
# power is re-supplied
# therefore we don't go into Standby
Exit
EndIf
%WAIT_SECS% = %WAIT_SECS% - 1
EndWhile
#
#
If (not ExternalPowered())
#
#
Set ON_AC_POWER_DAEMON, "\My Flash Disk\programme\MortScript\ON_AC_POWER_DAEMON.exe"
#
# note: the turn OFF exe here defined must be the same as defined in file
# POWERNOTIFIER_PROMPT.mscr
#
#
Set TURN_OFF, "\My Flash Disk\SystemProgs\Sleep.exe"
Set TOGGLE_DISPLAY, "\My Flash Disk\SystemProgs\ToggleDisplay.exe"
Sleep 100
If ( %PLAY_SOUND % )
PlaySound( %WAV_FILE% )
EndIf
#
# On suspend mode we set ACPower=0 (OFF)
IniWrite( %INI%, %INI_SECTION%, %INI_KEY%, "0" )
Sleep 100
%INI_KEY% = "ExtPowerOff"
#
# read in registry value
ExtPowerOff = \
RegRead (%REG_POWER_HIVE%, %REG_POWER_PATH%, \
%INI_KEY%)
Sleep 100
#
# remember this value
IniWrite( %INI%, %INI_SECTION%, %INI_KEY%, ExtPowerOff )
Sleep 100
#
# set our corresponding registry value
# i.e. always turn off device in 1 second even if AC powered
# note:
# this will be revised laterly with ON_AC_POWER_RESUME script
RegWriteDword (%REG_POWER_HIVE%, %REG_POWER_PATH%, \
%INI_KEY%, 4)
Sleep 100
#
# kill old notification(s) to prevent overlap
RemoveNotifications( %ON_AC_POWER_DAEMON% )
#
# set new notify (will be processed in CHECK_BACK_SECS from now on)
ReRun = TimeStamp() + %CHECK_BACK_SECS%
RunAt( ReRun, %ON_AC_POWER_DAEMON% )
Sleep 100
#
#
# turn device into standby
Run( %TURN_OFF% )
#
#
EndIf
#
#
Exit

# ON_AC_POWER_DAEMON.mscr
#
# jwoegerbauer 09/04/2009
# GNU General Public License (GPL), Version 2, June 1991
#
#
#
# NO ERROR CHECKING IS DONE !!!
#
#ErrorLevel("off")
Local()
#
#
# adjust to your needs (seconds !!!!)
Set CHECK_BACK_SECS, 15
#
#
Set ON_AC_POWER_DAEMON, "\My Flash Disk\programme\MortScript\ON_AC_POWER_DAEMON.exe"
Set ON_AC_POWER_RESUME, "\My Flash Disk\programme\MortScript\ON_AC_POWER_RESUME.exe"
Set TURN_OFF, "\My Flash Disk\SystemProgs\Sleep.exe"
Sleep 100
#
#
# kill old notification(s) to prevent overlap
RemoveNotifications( %ON_AC_POWER_DAEMON% )
Sleep 100
#
# check AC power line state
If( NOT ExternalPowered() )
#
# set new notify (will be processed in CHECK_BACK_SECS from now on)
ReRun = TimeStamp() + %CHECK_BACK_SECS%
RunAt( ReRun, %ON_AC_POWER_DAEMON% )
Sleep 100
#
# set another new notify
ReRun = TimeStamp() + 5
RunAt( ReRun, %TURN_OFF% )
#
#
Else
#
# call our application (script)
RunWait( %ON_AC_POWER_RESUME% )
#
#
EndIf
#
#
Exit

# ON_AC_POWER_RESUME.mscr
#
# jwoegerbauer 09/04/2009
# GNU General Public License (GPL), Version 2, June 1991
#
#
#
# NO ERROR CHECKING IS DONE !!!
#
ErrorLevel("off")
#
# Before using this script ensure file PowerNotifyFlags.ini
# is present and contains the following lines:
#
# [PowerOnOff]
# ACPower=1/0
#
Local()
#
#
# adjust to your needs
Set PLAY_SOUND, 1
Set WAV_FILE, "\My Flash Disk\programme\TroNikPowerNotifier\chime_up.wav"
Sleep 50
#
# prevent ourselves from doing things more than once
If (ExternalPowered())
#
#
If (%PLAY_SOUND% )
PlaySound( %WAV_FILE% )
EndIf
#
#
Set INI, "\My Flash Disk\programme\TroNikPowerNotifier\PowerNotifyFlags.ini"
Set INI_SECTION, "PowerOnOff"
Set INI_KEY, "ACPower"
Sleep 100
#
# Read PowerFlag value
ACPower = IniRead( %INI%, %INI_SECTION%, %INI_KEY% )
#
#
If(0 = ACPower)
#
# set ACPower=1 (ON)
IniWrite( %INI%, %INI_SECTION%, %INI_KEY%, "1" )
Sleep 100
#
#
EndIf
#
#
EndIf
#
#
Exit

THX in advance