MortScript-Manual.pdf

(612 KB) Pobierz
15984540 UNPDF
MortScript V4.1
(c) Mirko Schenk
mort@sto-helit.de
http://www.sto-helit.de
Contents
1 What is MortScript? / License . ....................................................................................................................... . 5
2 Functional range . ............................................................................................................................................. 5
3 Installation . ...................................................................................................................................................... 6
3.1 Different MortScript variations . ............................................................................................................................... 6
3.2 PC Setup . .................................................................................................................................................................. 6
3.3 CAB file . .................................................................................................................................................................. 6
3.4 Binaries . ................................................................................................................................................................... 6
4 Usage . .............................................................................................................................................................. 7
4.1 Create and execute scripts . ....................................................................................................................................... 7
4.2 Parameters for MortScript.exe . ................................................................................................................................ 7
4.3 Multiple instances and aborting scripts . ................................................................................................................... 7
5 Additional tools . .............................................................................................................................................. 8
5.1 Execute scripts when a storage card is inserted or removed . ................................................................................... 8
5.2 “Dummy exe” for scripts . ........................................................................................................................................ 8
5.3 Supporting scripts for CAB installations (setup.dll) . ............................................................................................... 8
6 Important general informations . ...................................................................................................................... 9
6.1 Glossary . .................................................................................................................................................................. 9
6.2 Syntax style in this manual . ..................................................................................................................................... 9
6.3 Spaces, tabulators, and line breaks . ....................................................................................................................... 10
6.4 Case sensitivity . ..................................................................................................................................................... 10
6.5 Directories and files . .............................................................................................................................................. 10
6.6 Comments . ............................................................................................................................................................. 10
7 Supported parameters and assignments . ....................................................................................................... 11
7.1 Expressions . ........................................................................................................................................................... 11
7.2 Data types . .............................................................................................................................................................. 12
7.3 Fixed strings . .......................................................................................................................................................... 12
7.4 Fixed numbers . ....................................................................................................................................................... 12
7.5 Variables . ............................................................................................................................................................... 13
Predefined variables . ............................................................................................................................................................................................. 13
Variable scope . ..................................................................................................................................................................................................... 14
Arrays (Lists) . ....................................................................................................................................................................................................... 15
References ([variable name]) . ............................................................................................................................................................................... 15
7.6 Operators . ............................................................................................................................................................... 16
List of all possible operators . ................................................................................................................................................................................ 16
Logical and binary operators . ............................................................................................................................................................................... 16
Comparisons . ........................................................................................................................................................................................................ 16
Concatenation of strings and paths . ...................................................................................................................................................................... 17
8 Control structures . ......................................................................................................................................... 18
8.1 Conditions . ............................................................................................................................................................. 18
8.2 Simple branchings (If) . .......................................................................................................................................... 18
8.3 Branching by values (Switch) . ............................................................................................................................... 19
8.4 Branching with selection dialog (Choice, ChoiceDefault) . ................................................................................... 19
8.5 Conditional loop (While) . ...................................................................................................................................... 20
8.6 Iteration over multiple values (ForEach) . .............................................................................................................. 20
Looping over INI file values (sections, values of a section) ................................................................................................................................ 21
Looping over registry entries (subkeys, values of a key) . .................................................................................................................................... 22
Looping over files and directories . ....................................................................................................................................................................... 22
8.7 Fixed number of repeatings (Repeat) . .................................................................................................................... 22
8.8 Simple iteration (For) . ............................................................................................................................................ 22
8.9 Sub routines (Sub, Call/CallFunction) . .................................................................................................................. 23
Manual for MortScript 4.1
Page 1 of 75
8.10 Other script as subroutine (CallScript/CallScriptFunction) . ................................................................................ 24
8.11 Set return value (Return) . ..................................................................................................................................... 24
8.12 Abort script (Exit) . ............................................................................................................................................... 24
9 Commands and functions . ............................................................................................................................. 25
9.1 Error handling (ErrorLevel) . .................................................................................................................................. 25
9.2 Variables . ............................................................................................................................................................... 26
Assigning variables (”=” and Set) . ....................................................................................................................................................................... 26
Expressions in a string (Eval) . .............................................................................................................................................................................. 26
Remove variable or array element (Clear) . ........................................................................................................................................................... 26
Check if variable is assigned (IsEmpty) . .............................................................................................................................................................. 26
Variable scope (Local, Global) . ............................................................................................................................................................................ 27
9.3 String operations . ................................................................................................................................................... 27
Get the length of a string (Length) . ...................................................................................................................................................................... 27
Extract a range of characters from a string (SubStr) . ........................................................................................................................................... 27
Split string and return a single part (Part) . ............................................................................................................................................................ 28
Find a string in another string (Find) . ................................................................................................................................................................... 28
Find last occurrence of a character (ReverseFind) . .............................................................................................................................................. 28
Replace strings (Replace) . .................................................................................................................................................................................... 29
Convert to upper / lower case (ToUpper/ToLower) . ........................................................................................................................................... 29
Parts of a filename (FilePath, FileBase, FileExt) . ................................................................................................................................................ 29
9.4 Math functions . ...................................................................................................................................................... 30
Formatted output (Format) . .................................................................................................................................................................................. 30
Conversion to/from hexadecimal (NumberToHex, HexToNumber) . ................................................................................................................... 30
Rounding (Round, Floor, Ceil) . ............................................................................................................................................................................ 30
Random values (Rand) . ........................................................................................................................................................................................ 31
Trigonometric functions (Sin, Cos, Tan) . ............................................................................................................................................................. 31
Logarithms (Log, Log10) . .................................................................................................................................................................................... 31
Square root (Sqrt) . ................................................................................................................................................................................................ 31
Compare float values (CompareFloat) . ................................................................................................................................................................. 31
9.5 Arrays . .................................................................................................................................................................... 32
Get biggest index in series (MaxIndex) . ............................................................................................................................................................... 32
Get number of elements (ElementCount) . ............................................................................................................................................................ 32
Create an array from a list of values (Array) . ....................................................................................................................................................... 32
Create an array with named indexes (Map) . ......................................................................................................................................................... 33
Spit a string to multiple variables/array elements (Split) ..................................................................................................................................... 33
9.6 Execute applications or open documents . .............................................................................................................. 34
Open application/document and continue script (Run) . ....................................................................................................................................... 34
Open application/document and wait until it's finished (RunWait) . .................................................................................................................... 34
Other script as sub routine (CallScript, CallScriptFunction) . ............................................................................................................................... 34
Create new document / element (New) . ............................................................................................................................................................... 34
Execute application at a given time (RunAt) . ....................................................................................................................................................... 35
Execute application on each power on (RunOnPowerOn) . .................................................................................................................................. 35
Remove application from „Notification Queue“ . ................................................................................................................................................. 35
9.7 Application windows . ............................................................................................................................................ 36
Window titles – how MortScript finds a window . ................................................................................................................................................ 36
Show and activate a window (Show) . ................................................................................................................................................................... 36
Minimize/hide a window (Minimize) . .................................................................................................................................................................. 36
Close a window / end application (Close) . ........................................................................................................................................................... 36
Get the title of the currently active window (ActiveWindow) . ............................................................................................................................ 36
Check whether a window is active (WndActive) . ................................................................................................................................................ 36
Check whether a window exists (WndExists) . ..................................................................................................................................................... 37
Wait until a window exists (WaitFor) . ................................................................................................................................................................. 37
Wait until a window becomes active (WaitForActive) ........................................................................................................................................ 37
Get window title / element contents (WindowText) . ............................................................................................................................................ 37
Get window position (GetWindowPos, WndLeft, -Right, -Top, -Bottom) . ......................................................................................................... 37
Send special commands (SendOK, SendCancel, SendYes, SendNo) . ................................................................................................................. 38
Send advanced commands/messages (SendCommand, SendMessage, PostMessage) . ....................................................................................... 38
9.8 Keystrokes . ............................................................................................................................................................. 39
Sending strings (SendKeys) . ................................................................................................................................................................................. 39
Sending special characters (e.g. direction keys) (Send...) . ................................................................................................................................... 39
Copy screen contents to clipboard (Snapshot) . ..................................................................................................................................................... 40
Sending Ctrl+key (SendCtrlKey) . ........................................................................................................................................................................ 40
9.9 Mouse clicks / tapping . .......................................................................................................................................... 41
Single click (MouseClick) . ................................................................................................................................................................................... 41
Double click (MouseDblClick) . ............................................................................................................................................................................ 41
Press / release the mouse button separated (MouseDown/MouseUp) . ................................................................................................................. 41
9.10 Waiting . ................................................................................................................................................................ 42
Fixed delay in milliseconds (Sleep) . ..................................................................................................................................................................... 42
Wait message with countdown / condition (SleepMessage) ................................................................................................................................ 42
Waiting for windows (WaitFor / WaitForActive) . ............................................................................................................................................... 42
9.11 Time . .................................................................................................................................................................... 43
Unix timestamp (TimeStamp) . ............................................................................................................................................................................. 43
Manual for MortScript 4.1
Page 2 of 75
Formatted output (FormatTime) . .......................................................................................................................................................................... 43
Set current time to multiple variables (GetTime) . ................................................................................................................................................ 44
9.12 Copy, rename, move, and delete files . ................................................................................................................. 45
Copy a single file (Copy) . ..................................................................................................................................................................................... 45
Copy multiple files (XCopy) . ............................................................................................................................................................................... 45
Rename or move a single file (Rename) . .............................................................................................................................................................. 45
Move multiple files (Move) . ................................................................................................................................................................................. 46
Delete file(s) (Delete) . .......................................................................................................................................................................................... 46
Delete files, also in subdirectories (DelTree) . ...................................................................................................................................................... 46
Creating a shortcut/link (CreateShortcut) . ............................................................................................................................................................ 46
9.13 Reading and writing text files . ............................................................................................................................. 47
Reading a text file (ReadFile) . .............................................................................................................................................................................. 47
Writing to a text file (WriteFile) . .......................................................................................................................................................................... 47
Reading a value of an INI file (IniRead) . ............................................................................................................................................................. 48
Writing a value to an INI file (IniWrite) . ............................................................................................................................................................. 48
Access serial ports (SetComInfo) . ........................................................................................................................................................................ 48
9.14 File system informations . ..................................................................................................................................... 49
Check whether file or directory exists (FileExists/DirExists) . ............................................................................................................................. 49
Check free space (FreeDiskSpace) . ...................................................................................................................................................................... 49
Check disk size (TotalDiskSpace) . ....................................................................................................................................................................... 49
Get file size (FileSize) . ......................................................................................................................................................................................... 49
Get file creation time (FileCreateTime) . .............................................................................................................................................................. 49
Get file modification time (FileModifyTime) . ..................................................................................................................................................... 49
Get file attributes (FileAttribs) . ............................................................................................................................................................................ 50
Set file attributes (SetFileAttribute, SetFileAttribs) . ............................................................................................................................................ 50
Get version number (FileVersion / GetVersion) . ................................................................................................................................................. 51
9.15 ZIP archives . ........................................................................................................................................................ 52
Important hints . ..................................................................................................................................................................................................... 52
Compress a single file (ZipFile) . .......................................................................................................................................................................... 52
Compress multiple files (ZipFiles) . ...................................................................................................................................................................... 53
Extract single file (UnzipFile) . ............................................................................................................................................................................. 53
Extract entire archive (UnzipAll) ......................................................................................................................................................................... 53
Extract a path of an archive (UnzipPath) . ............................................................................................................................................................. 54
9.16 Connections . ......................................................................................................................................................... 55
Establish connection (Connect) . ........................................................................................................................................................................... 55
End connection (CloseConnection/Disconnect) . .................................................................................................................................................. 55
Check connection (Connected/InternetConnected) . ............................................................................................................................................. 56
9.17 Internet access . ..................................................................................................................................................... 56
Set proxy . .............................................................................................................................................................................................................. 56
Download (Download) . ........................................................................................................................................................................................ 56
Other possibilities . ................................................................................................................................................................................................ 56
9.18 Directories . ........................................................................................................................................................... 57
Create directory (MkDir) . ..................................................................................................................................................................................... 57
Remove directory (RmDir) . .................................................................................................................................................................................. 57
Change directory (ChDir) . .................................................................................................................................................................................... 57
Getting system paths (SystemPath) . ..................................................................................................................................................................... 57
9.19 Registry . ............................................................................................................................................................... 58
Reading registry entries (RegRead) . ..................................................................................................................................................................... 58
Writing registry entries (RegWriteString/RegWriteDWord/ RegWriteBinary/RegWriteMultiString) . .............................................................. 58
Checking existence of a value (RegValueExists) . ................................................................................................................................................ 59
Checking existence of a key (registry path) (RegKeyExists) . .............................................................................................................................. 59
Removing a registry value (RegDelete) . .............................................................................................................................................................. 59
Removing a registry key (registry path) (RegDeleteKey) . ................................................................................................................................... 59
9.20 Dialogs . ................................................................................................................................................................ 60
Free text input (Input) . .......................................................................................................................................................................................... 60
Message (Message) . .............................................................................................................................................................................................. 60
Big message with scrollbar (BigMessage) . .......................................................................................................................................................... 60
Message with countdown/condition (SleepMessage) . .......................................................................................................................................... 60
Simple questions (Question) . ................................................................................................................................................................................ 61
Selection from a list (Choice) . .............................................................................................................................................................................. 61
Select directory (SelectDirectory) . ....................................................................................................................................................................... 61
Get filename (SelectFile) . ..................................................................................................................................................................................... 62
Set entry size and font for choices (SetChoiceEntryFormat) ............................................................................................................................... 62
Set font for big messages (SetMessageFont) . ....................................................................................................................................................... 62
9.21 Processes (running applications) . ......................................................................................................................... 63
Process handling supported? (SupportsProcHandling) . ....................................................................................................................................... 63
Checking existence of a process (ProcExists) . ..................................................................................................................................................... 63
Checking existence of a script process (ScriptProcExists) . .................................................................................................................................. 63
Process name of active window (ActiveProcess) . ................................................................................................................................................ 63
Process name of given window (WindowProcess) . .............................................................................................................................................. 64
End a running process (Kill) . ................................................................................................................................................................................ 64
End a running script (KillScript) . ......................................................................................................................................................................... 64
9.22 Signals . ................................................................................................................................................................. 65
Manual for MortScript 4.1
Page 3 of 75
Modifying the system volume (SetVolume) . ....................................................................................................................................................... 65
Play a WAV file (PlaySound) . .............................................................................................................................................................................. 65
Vibrate (Vibrate) . .................................................................................................................................................................................................. 65
9.23 Display / screen . ................................................................................................................................................... 66
Get the color at a screen position (ColorAt) . ........................................................................................................................................................ 66
Create the color code from RGB values (RGB) . .................................................................................................................................................. 66
Get the red/green/blue part of a color code (Red, Green, Blue) . .......................................................................................................................... 66
Rotate the screen (Rotate) . .................................................................................................................................................................................... 66
Set backlight intensity (SetBacklight) . ................................................................................................................................................................. 66
Toggle display on/off (ToggleDisplay) . ............................................................................................................................................................... 67
Get screen size (ScreenWidth, ScreenHeight) . ..................................................................................................................................................... 67
Check screen informations (orientation/resolution) (Screen) . .............................................................................................................................. 67
Redraw today screen (RedrawToday) . ................................................................................................................................................................. 67
Show/hide wait cursor (ShowWaitCursor/HideWaitCursor) ............................................................................................................................... 67
9.24 Clipboard . ............................................................................................................................................................. 68
Copy text to the clipboard (SetClipText) . ............................................................................................................................................................. 68
Get text from the clipboard (ClipText) . ................................................................................................................................................................ 68
9.25 Memory . ............................................................................................................................................................... 68
Available main memory (FreeMemory) . .............................................................................................................................................................. 68
Size of the main memory (TotalMemory) . ........................................................................................................................................................... 68
9.26 Energy . ................................................................................................................................................................. 69
Check if externally powered (ExternalPowered) . ................................................................................................................................................. 69
Current battery level (BatteryPercentage, BackupBatteryPercentage) . ................................................................................................................ 69
Turn off device (PowerOff) . ................................................................................................................................................................................. 69
Avoid automatic power off (IdleTimerReset) . ..................................................................................................................................................... 69
9.27 System . ................................................................................................................................................................. 70
Get the system version (SystemVersion) . ............................................................................................................................................................. 70
Get the current MortScript variant (MortScriptType) . ......................................................................................................................................... 70
Get the current MortScript version (MortScriptVersion, GetMortScriptVersion) . .............................................................................................. 70
Restart device (Reset) . .......................................................................................................................................................................................... 70
10 Old syntax and commands . ......................................................................................................................... 71
10.1 Old syntax . ........................................................................................................................................................... 71
10.2 Old conditions . ..................................................................................................................................................... 71
10.3 Old commands . .................................................................................................................................................... 73
11 Donations . ................................................................................................................................................... 75
Manual for MortScript 4.1
Page 4 of 75
1 What is MortScript? / License
MortScript is "just" an interpreter (similar to the runtime environment of Visual Basic), so there's no
visible program that can be run for itself. (Except for the registration of file extensions when you
run MortScript.exe, but that's unnecessary if you used an installer – also see 3 Installation )
The script language is focused on batch control, i.e. to run other applications and remote control
them, and to do basic system operations, like file operations, registry modifications, and such. Due
to this, only basic dialogs are available.
You have to use downloaded .mscr or .mortrun script files, or write them yourself with any text
editor (see 4.1 Create and execute scripts ) . For beginners, writing own scripts might be a bit
complicated.
You can execute those scripts by running them like any other application in the file explorer (i.e.,
just tap the file), or create a shortcut to those files in your start menu (\Windows\Start menu, or
some localization) with the file explorer (or any other tool).
I don't grant any warranty for damages caused by this program (neither me nor the script authors are
perfect...). Be aware that foreign scripts can do lots of dangerous things, just like any "normal"
application can read or delete files, or send data via the internet.
MortScript is freeware, i.e., you don't need to pay for it, but I'd be glad about a small (or big ;))
donation as "thank you!". See also 11 Donations .
The source is available on request (SubVersion repository), but unlike e.g. GPL, you're not allowed
to create your own derivate – that's to avoid a “For that script, you've got to use the XxxScript
interpreter from Yyy” confusion.
You may deploy MortScript with your own scripts, even for commercial scripts (be aware they will
be available in source code since there's no compiled code...). But you have to note at a sensible
location (readme.txt, setup, or similar) that MortScript is a foreign product with its own license. A
link to my web site or mentioning my name would be good manner (e.g. „MortScript is freeware,
www.sto-helit.de“).
2 Functional range
MortScript supports among others.:
Run, activate, hide, and close applications
Wait functions: certain timespan, wait for existence or activation of windows
Send keystrokes and mouse clicks to windows
Copy, rename, move, delete files, create shortcuts
Create and remove directories
Supports ZIP archives (no overwriting of contained files!)
Read and write text files
Read and modify the registry
Internet: Reading text files, downloads, create and close connections
If conditions, Choice selections and For-, ForEach, While or Repeat loops
Some system features (e.g. rotation, volume, backlight brightness, soft reset)
Sub functions, local variables, multi level arrays, ...
Manual for MortScript 4.1
Page 5 of 75
Zgłoś jeśli naruszono regulamin