MortScript examples accumulation

Search This thread

michoob

Retired Recognized Developer
Dec 19, 2008
1,270
65
Brussels
Hi mariasx, I don't think your problem comes from the "foreach record in Array", but rather from the massive amount of string operations (Replace, Find, SubStr, Split)!
There is definitly something to do around these string operations...

I do not have much time to spend, but an idea might be trying to recode the whole script to avoid using all these string operations, but to use the IniRead and IniWrite functions and to store your data in a .ini file, where you would have a .ini section per your current csv column, and a code for each task... not sure if it would be better.
 

mariasx

Member
Jul 23, 2008
13
1
Bratislava
Hi michoob

1. Thank you for answer. I did not change data(Strings operations). I tried to display different lists(Foreach record in Array) and performance was decreasing. So I think there is problem with memory and I do not know how to handle it.

2. How do you think data should be designed in INI file?

like that?

[lorem]
desc=Nam posuere iaculis
status=n
context=movies

[ipsum]
desc=pretium eu leo
status=n
context=movies
 

michoob

Retired Recognized Developer
Dec 19, 2008
1,270
65
Brussels
1. I do not say you change the data, but you obviousely use string operations for the display in your Foreach loop, and that is why performance is decreasing. And it is not decreasing because of memory, but rather because of CPU...
You might try to use MortScript 4.3b15 if not already the case, because it is faster.

2. Nope, I would rather see it like this, but then, the data is of course less readable than a csv file (but do yo care?):
[reference]
1=lorem
2=ipsum

[desc]
1=Nam posuere iaculis
2=pretium eu leo

[status]
1=n
2=n

[context]
1=movies
2=movies
 

RoryB

Inactive Recognized Developer
Sep 4, 2008
2,921
766
Lexington
Sad to go

My Fuze no longer works. I currently have a loner Infuse 4G, but do not know what I will end up with.

I will not be able to continue development of Mortscripts, etc.

Sorry to go, but it has been fun.

I'll keep watching to see if anything comes up I need to respond to.
 

mariasx

Member
Jul 23, 2008
13
1
Bratislava
The loaner is a Droid, but I do not know what I'll end up with. So I am in limbo.

I have an Android device too. For a six months I am still looking for Mortscript replacement for Android. I found some candidate like BASIC! + SQL. Even better could be Frink Programming Language but it still do not adequately meets Mortscript quallities.

I need one programming language for phone and desktop and Java is not what I am talking about. Adobe Flex is also an possible alternative.

Maybe Windows 8 will be salvation because it is Intel and also Arm processor compatible. I am curious.
 

lesscro

Senior Member
Jul 16, 2007
4,486
2,266
Paris
Thx for all RoRyB... you help lot of time and insipre me more than lot of time...

See yaaa in other place... ;)
 
D

Deleted member 1890170

Guest
Searching for control structure errors

I have a script with ~3,300 lines. Script is organized in parts MAIN and SUBS. Suddenly got error "Sub must not be in control structure". I know this errror only occurs if If/EndIf is not matching. Re-reading the script again and again I didn't find the missing EndIf. Hence decided to write a small script as listet next to make searching for the error cause easier
Code:
local()
Thoght I should share this script.
 
Last edited by a moderator:

vivekiny2k

Senior Member
Oct 31, 2010
69
4
Well, I figured out a simple script myself :). This allows you to not use an HTC PhoneCanvas and still retain the use of the proximity sensor if your phone has one. In my case, this allows me to use Iconsoft PhonEx and have the screen turn off when next to my ear and turn on when held away from your ear.
Code:
If (RegValueExists("HKLM", "System\State\Phone", "Active Call Count") = FALSE)
RegWriteDWord("HKLM", "System\State\Phone", "PSensorStatus", 0)
ElseIf (RegValueExists("HKLM", "System\State\Phone", "Active Call Count") = TRUE)
RegWriteDWord("HKLM", "System\State\Phone", "PSensorStatus", 1)

does anybody know if there are keys/values in registry to find if
1. the phone is ringing.
2. the call is on (I believe the script mentioned above will work for that.)

it might help somebody. I wrote a script to play-pause, write the current song info in a file (because I keep losing my last pause point), and execute voice command if the music is paused. I ended up using screen off for nitrogen because poweroff or toggledisplay cause it to stop playing.

Code:
RunStatus=RegRead("HKLM","System\State\Nitrogen","Running")
If (Runstatus eq 1)
    SendCommand("Nitrogen",40001)
    sleep(1000)
    WriteFile("nitrogen-status.txt","^NL^",TRUE)
    CurrentTime = FormatTime( "y/m/d:h:i:s", TimeStamp() )
    WriteFile("nitrogen-status.txt","""CurrentTime:" & CurrentTime & "",TRUE)
    SongTitle=RegRead("HKLM","System\State\Nitrogen","SongTitle")
    WriteFile("nitrogen-status.txt","""SongTitle:" & SongTitle & "",TRUE)
    TimeElapsed=RegRead("HKLM","System\State\Nitrogen","TimeElapsed")
    WriteFile("nitrogen-status.txt","""TimeElapsed:" & TimeElapsed & "",TRUE)
    TimeTotal=RegRead("HKLM","System\State\Nitrogen","TimeTotal")
    WriteFile("nitrogen-status.txt","""TimeTotal:" & TimeTotal & "",TRUE)
    PlayStatus=RegRead("HKLM","System\State\Nitrogen","PlayStatus")
    If (PlayStatus lt 2)
        Setvolume(150)
        run("\windows\start menu\programs\voice speed dial.lnk")
        sleep(10000)
        Poweroff()
    Else
        Setvolume(200)
        run("\windows\start menu\programs\screen off.lnk")
    Endif
Else
    Setvolume(150)
    run("\windows\start menu\programs\voice speed dial.lnk")
    sleep(10000)
    Poweroff()
EndIf
 
Last edited:

vivekiny2k

Senior Member
Oct 31, 2010
69
4
since I coudln't find a way to get the weather on lock screen cpr file, I used following script to show weather in place of operator name when end key is pressed on lock screen. I am also think about updating the weather on double click.

Code:
If (RegValueExists("HKLM", "System\State\Phone", "Active Call Count") = FALSE)
        LockStatus=RegRead("HKLM","System\State","Lock")
        if (LockStatus gt 0)        
            WeatherStatus=RegRead("HKLM","Software\Microsoft\CHome\TitaniumWeather\CondensedPage","PluginLabel")
            Weathertime=RegRead("HKLM","Software\Microsoft\CHome\TitaniumWeather\Page1","Time")
            TimeLocation=Find(Weathertime,"Updated at")
            UpdateTime=Substr(Weathertime,TimeLocation + 10,9)
            RegWriteString("HKLM","System\State\Phone","Current Operator Name",WeatherStatus & UPdateTime)
        else
            Run("\Program Files\AEBPlus\AEBPlus.exe", 0021)
        endif
Else
    Run("\Program Files\AEBPlus\AEBPlus.exe", 0021)        
Endif
 

kastel71

Senior Member
Dec 9, 2008
117
27
[HELP] how can I ...in Mortscript

I have a "gps.ini" file these parameters:
Code:
Port = 4
Baudrate = 56000

And I have a "sys.txt" file these parameters:
Code:
[gps]
port = "1"
baud = "4800"

I want to read the parameters values from "Port"and "Band from "gps.ini" and write them in the "sys.txt"

How can I do this with mortscript?
 

RoryB

Inactive Recognized Developer
Sep 4, 2008
2,921
766
Lexington
I have a "gps.ini" file these parameters:
Code:
Port = 4
Baudrate = 56000

And I have a "sys.txt" file these parameters:
Code:
[gps]
port = "1"
baud = "4800"

I want to read the parameters values from "Port"and "Band from "gps.ini" and write them in the "sys.txt"

How can I do this with mortscript?
Does your gps.ini have a [section] defined?

9.13.3 Reading a value of an INI file (IniRead)
string = IniRead( file name, section, entry )
Reads an entry from an INI file. The section name must be passed without the brackets.
Example:
x = IniRead( "\My documents\test.ini", "Settings", "Test" )

9.13.4 Writing a value to an INI file (IniWrite)
IniWrite( file name, section, entry, value )
Writes an entry to an INI file. The section name must be passed without the brackets.
Be aware this causes MortScript to load, parse, and write the entire file. It might be better to do this
yourself (ReadFile, ForEach with split, WriteFile) if many values are modified.
Example:
IniWrite( "\My documents\test.ini", "Settings", "Test", "x" )

IniWrite( "\path to file\sys.txt", "gps", "port", IniRead( "\path to file\gps.ini", "gps", "port") )
IniWrite( "\path to file\sys.txt", "gps", "band", IniRead( "\path to file\gps.ini", "gps", "band") )
 

Mister B

Senior Member
Sep 14, 2006
2,087
386
Ratchada (Bangkok)
tmail.exe ActiveWindow

on Wm6.5 what is the active window title for tmail sms & email accounts.
trying to map a buttons function for specific use while in sms & accounts but can't get ActiveWindow command to recognise tmail.
 

Mister B

Senior Member
Sep 14, 2006
2,087
386
Ratchada (Bangkok)
i'm using SMS / MMS as window title & with ElseIf ActiveWindow SMS / MMS it does not see tmail window active & carries out another base command from the script.
 

bbobeckyj

Senior Member
Aug 4, 2006
963
10
dorset
What happens when you use this script while tmail is active?

Sleep (5000)
Aw = activeWindow ()
Message (aw)


I recently gave up my HD2 as it started to die so unfortunately I can't test this myself, but I did keep a backup of all my WM6.5 stuff, I'm just checking through it...
 

Top Liked Posts

  • There are no posts matching your filters.
  • 3
    MortScripts to toggle settings

    Thread started today for MortScripts that can be used in CHTS. They started as a supplement to CHTS, but they can be used outside it too.

    So far I have radio band changer and sound profile changer scripts.

    MortScripts to toggle settings
    2
    D
    Deleted member 1890170
    fileMask="I*.jpg"
    startDir="\storage card\DCIM\100MEDIA"
    recurse=1

    @RenameFiles(startDir,fileMask,recurse)

    Sub RenameFiles(startDir,fileMask,recurse)
    Local()
    ForEach found In Files(startDir\fileMask)
    time=FormatTime("Ymd",FileModifyTime(found))
    name=FileBase(found)
    newFullFilePathName=FilePath(found)&"\"&SubStr(name,1,1,)&time&FileExt(found)
    Rename(found,newFullFilePathName)
    Sleep(1)
    EndForEach
    If(recurse)
    ForEach startDir2 In Directories(startDir\"*")
    @RenameFiles(startDir2,fileMask,recurse)
    EndForEach
    EndIf
    EndSub
    2
    D
    Deleted member 1890170
    Is anywhere a small graphic menu to get inspiration?
    By-look here: http://xdaforums.com/showthread.php?t=1368340
    1
    Hello, I've a problem.

    I would want to create a script to set the registry of system of mine pna C220.
    In this way to every reset this script runs and in automatic configures the registry for me and launch my software preferred (pollicino).

    This is the script:
    Code:
    Errorlevel ("off")
    
    #RegWriteDWord ("HKLM", "System\CurrentControlSet\Control\Power", "DisableGwesPowerOff", "0")
    #RegWriteDWord ("HKLM", "System\CurrentControlSet\Control\Power\ActivityTimers\UserActivity", "Timeout", "0")
    #RegWriteDWord ("HKLM", "System\CurrentControlSet\Control\Power\ActivityTimers\SystemActivity", "Timeout", "0")
    #RegWriteDWord ("HKLM", "System\CurrentControlSet\Control\Power\State\UserIdle", "Default", "0")
    #RegWriteDWord ("HKLM", "System\CurrentControlSet\Control\Power\State\SystemIdle", "Default", "0")
    #RegWriteDWord ("HKLM", "System\CurrentControlSet\Control\Power\Timeouts", "BattSystemIdle", "0")
    #RegWriteDWord ("HKLM", "System\CurrentControlSet\Control\Power\Timeouts", "BattUserIdle", "0")
    #RegWriteDWord ("HKLM", "System\CurrentControlSet\Control\Power\Timeouts", "ACSystemIdle", "0")
    #RegWriteDWord ("HKLM", "System\CurrentControlSet\Control\Power\Timeouts", "ACUserIdle", "0")
    #RegWriteDWord ("HKLM", "System\CurrentControlSet\Control\Power\Timeouts", "ACSuspend", "0")
    #RegWriteDword ("HKLM", "System\CurrentControlSet\Control\Power\Timeouts", "BattSuspend", "0")
    #RegWriteDword ("HKLM", "System\CurrentControlSet\Control\Power\Timeouts", "BatteryPoll", "0")
    
    #RegDeleteKey ("HKLM", "System\CurrentControlSet\Control\Power\ActivityTimers", True, True)
    #RegDeleteKey ("HKLM", "System\CurrentControlSet\Control\Power\State\SystemIdle", True, True)
    #RegDeleteKey ("HKLM", "System\CurrentControlSet\Control\Power\State\UserIdle", True, True)
    #RegDeleteKey ("HKLM", "System\CurrentControlSet\Control\Power\Timeouts", True, True)
    
    #SetVolume (255)
    
    Run("\Storage Card\Pollicino\Pollicino.exe")
    #Sleep (15000)
    Waitfor("Pollicino", 1000)
    while (WndActive ("Pollicino"))
    sleep(100)
    endwhile
    Kill("Pollicino.exe")
    
    
    Exit
    
    #*********************************************************************
    Is the script correct?

    Well, I have try to launch it but I have read this errore message:
    ".mscr and .mortrun extension registered.
    Please run any .mscr/.mortrun file ..."

    What's the problem? Is the Wrong script or other?

    I have set a button to launch this script:
    Code:
    ICONXPBUTTON
    X = 36
    Y = 71
    Command = \Storage Card\Pollicino.exe
    SizeNormal = 48
    SizePushed = 48
    Gray = no
    ScaleAlpha = 100
    IconNormal = \my flash disk\C220\skin\icons\Pollicino.ico
    Gray = no
    ScaleAlpha = 100
    IconPushed = \my flash disk\C220\skin\icons\Pollicino.ico

    In Storage Card I have:
    - Pollicino folder (inside Pollicino.exe)
    - Mosrtscript.exe (v.4.2)
    - Pollicino.exe (Mortscript.exe (v.4.2) renamed)
    - Pollicino.mscr
    - setup.dll
    - mortzip.dll

    Please help me

    Well, the script itself looks good, except you've commented out all your registry commands... take out the "#" from each line, if you actually want them to run.

    However, if you want to use an EXE file to launch a MortScript like you are trying to do, you don't rename MortScript.exe to Pollicino.exe, you rename Autorun.exe to Pollicino.exe. Also, you do not need setup.dll or mortzip.dll, those are if you are making a cab file.

    Although looking at it, you have the button launch \Storage Card\Pollicino.exe... is that supposed to be the one that launches the script? If so, the script needs to be in \Storage Card\Pollicino.mscr, and there should be \Storage Card\MortScript.exe there also (if it's not there, it looks for an installed version on your device). Better to have those in a folder, would think, and change the button launching to launch from the folder. I'm assuming that \Storage Card\Pollicino\Pollicino.exe is NOT supposed to be running a script, but some other program?

    Edit:
    It seems to me that this:
    Code:
    Run("\Storage Card\Pollicino\Pollicino.exe")
    #Sleep (15000)
    Waitfor("Pollicino", 1000)
    while (WndActive ("Pollicino"))
    sleep(100)
    endwhile
    Kill("Pollicino.exe")
    could most likely be changed to this:
    Code:
    RunWait("\Storage Card\Pollicino\Pollicino.exe")
    Assuming that the program closes itself, of course... Or do you want to have it killed when the window is no longer active?
    1
    I have done tinkered with PNA devices. Is the CE running on them the same as a PDA? I did a quick search and it seems to say the CE running on a PNA has limited access to CE functions. Maybe it does not allow wildcards as a result of this.