API's for External Programs/Scripts Interaction  >

www.MacroToolworks.com

Command Line Executable

 

The Macro Toolworks Professional edition (and Free Macro Player) comes with MtwProxy.exe command line executable. It provides other programs or scripts access to the variables and macros in running Macro Toolworks. Other programs can use MtwProxy.exe to set or retrieve a value of an application global variable (the one that starts with "ga_" prefix - see more here - or a system variable - see more here), and start an existing macro and retrieve its result.

 

MtwProxy.exe Command Line API Commands

 

Command

Description

getver

Writes version (such as "9.2.0") of the  Macro Toolworks Professional edition (or Free Macro Player) to the standard output.

MtwProxy.exe getver

getname

Writes program name (such as Macro Toolworks) to the standard output.

MtwProxy.exe getname

getvar

Retrieves a variable value and writes it to the standard output.

MtwProxy.exe getvar <VARIABLE_NAME>

VARIABLE_NAME - a string that specifies an existing global application scope variable (starting with "ga_" prefix) or a system variable. It can be also an array element (for example, "ga_MyArray[3]).

 

Example:  MtwProxy.exe getvar _vClpText
This call will the text currently stored in the clipboard to the standard output.

setvar

Sets the variable value and writes "1" (on success) or "0" (on fail) to the standard output.

MtwProxy.exe setvar <VARIABLE_NAME> <NEW_VALUE>

VARIABLE_NAME - a string that specifies an existing global application scope variable (starting with "ga_" prefix) or a system variable. It can be also an array element (for example, "ga_MyArray[3]).

NEW_VALUE - a string that will be assigned as a value to the variable.

 

Example 1:  MtwProxy.exe setvar ga_Temperature 97

Example 2: 

MtwProxy.exe setvar ga_CustomerName[0] "John J. James"

MtwProxy.exe setvar ga_CustomerName[1] "Marion M. Marr"

runmacro

Runs an existing macro. Waits until the macro finishes and writes its result to the standard output.

MtwProxy.exe runmacro <MACRO_NAME> <PARAMETER>

MACRO_NAME - a string that specifies a name of the existing macro.

PARAMETER - a string that will be passed to the macro as the parameter.

 

Example: 

Let's have a macro named "cmdTest":

 

<msg>(-100,-100,"Http Test: %_vMacroParameter%","",1,0,0,0)<#>

<varset>("_vMacroResult=Goodbye","")

 

Let's run this command in Command Line window:

MtwProxy.exe runmacro cmdTest Hello

 

The macro will be called. It will display a message box with "Hello" text. When the message box is closed text "Goodbye" is written to the Command Line window.

 

 

The data written to the standard output is in UTF-8 encoding. The executable returns 0 on success or -1 on error. You need to manually add path to the MtwProxy.exe to your "Path" environment variable if you want to use the MtwProxy.exe without the full path in scripts (as shown in the example below). The default path is c:\Program Files (x86)\Macro Toolworks\Bin  (or c:\Program Files (x86)\Free Macro Player\Bin).

 

Example (.bat)

 

Let's have a macro named "cmdTest":

 

<msg>(-100,-100,"cmdTest: %_vMacroParameter%","",1,0,0,0)<#>

<varset>("_vMacroResult=Goodbye","")

 

Let's run this .bat file in Command Line window:

 

@echo OFF

 

for /F "delims=" %%a in ('MtwProxy.exe runmacro cmdTest "Hello, World!"') do set result=%%a

 

IF %ERRORLEVEL% NEQ 0 (

   @echo FAIL

   EXIT /B

)

 

@echo %result%

@echo OK

 

Result: The macro will be called. It will display a message box with "Hello, World!" text. When the message box is closed text "Goodbye" is echoed in the Command Line window.