Http API
The Macro Toolworks Professional edition (and Free Macro Player) program supports (starting version 9.2.0) an HTTP API. It allows other programs 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.
HTTP Ports
The program starts an HTTP server that listens (for localhost / 127.0.0.1 only) for HTTP requests on the following ports:
Program |
Ports |
Macro Toolworks |
29592 - primary port 40804 - secondary port if the primary port is in use by other program 45054 - other port if the primary and secondary port is in use by other program |
Free Macro Player |
29593 - primary port 40805 - secondary port if the primary port is in use by other program 45055 - other port if the primary and secondary port is in use by other program |
The actual port (most likely primary port) used by the program is logged in the log file.
HTTP API Commands
Command |
Description |
getver |
Returns version of the program listening on the given port (such as "9.2.0"). http://127.0.0.1:29592/getver |
getname |
Returns the name of the program listening on the given port (such as "Macro Toolworks"). http://127.0.0.1:29592/getname |
getvar |
Returns the variable value. http://127.0.0.1:29592/getvar?name=<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: http://127.0.0.1:29592/getvar?name=_vClpText |
setvar |
Sets the variable value. The request returns "1" on success or "0" if it fails. http://127.0.0.1:29592/setvar?name=<VARIABLE_NAME>&value=<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: http://127.0.0.1:29592/setvar?name=ga_Temperature&value="97" Example 2: http://127.0.0.1:29592/setvar?name=ga_CustomerName[0]&value="John J. James" http://127.0.0.1:29592/setvar?name=ga_CustomerName[1]&value="Marion M. Marr" |
runmacro |
Runs an existing macro. Waits until the macro finishes and returns its result. http://127.0.0.1:29592/runmacro?name=<MACRO_NAME>¶m=<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 "httpTest":
<msg>(-100,-100,"httpTest: %_vMacroParameter%","",1,0,0,0)<#> <varset>("_vMacroResult=Goodbye","")
Let's make this request: http://127.0.0.1:29592/runmacro?name=httpTest¶m=Hello
The macro will be called. It will display a message box with "Hello" text. When the message box is closed the request returns "Goodbye".
|
The API supports UTF-8 encoding.
C# HTTP Client Code Example
namespace HttpClientCSharp
{
class Program
{
static async Task Main(string[] args)
{
using var client = new HttpClient();
var value = await client.GetStringAsync("http://127.0.0.1:29592/getvar?name=ga_vMyVariable");
Console.WriteLine(value);
}
}
}