What Is The MacroScript SDK?
The MacroScript Software Development Kit is a software component that allows developers to use the Macro Scheduler scripting language within their own applications. It comes in ActiveX and DLL form so that almost any programming language, including VB, C#, C++, Delphi, PowerBuilder, etc, can make use of it. It makes it possible for other applications to run Macro Scheduler code internally. As well as run Macro Scheduler code it allows the programmer to query or modify MacroScript variables at any point during execution.
Who Would Use It and Why?
The SDK is aimed at application developers. It is commonly used in projects where some integration is needed with other third party or legacy applications where no API exists, or where the developer needs to provide a means of creating macros within their applications.
For example, DM Software in Denmark used it in their Dialog Manager product to simplify integration with other systems and share data with them, as well as allow their users to create scripts for custom integrations. You can read the case study here.
Why Not Just Compile a Macro with Macro Scheduler Pro and “shell” it?
If all you want to do is have your application run a Macro Scheduler macro to perform some automation, then, sure, all you really need to do is compile your macro to a .exe and then call or “shell” this .exe from your application. E.g. using the VB/VBA Shell function.
This might be fine if that is really all you need to do. But what if you want to get data back from the macro? Let’s say the macro scrapes data from a web page and you need to get this data back into your calling application. This would be difficult to do with an external .exe. While you could use temporary file storage or a database and have your .exe macro write the data out and then read it back in with your application, this requires extra work and validation. You also have to consider the implications of the external macro process being terminated prematurely, perhaps by the user.
With the SDK you can execute script code directly from within your application in whole, or in sections or even one line at a time. And between lines or code sections you can directly query the value of a variable or variables. So using the SDK you have much greater control, there is no need to handle shelling out to an external process, waiting for it to complete and reading/writing to file. Instead you can control the logic flow as you wish and access macro data directly, storing it in local variables as and when needed.
– Control of logic flow
– Direct access to script variables
– No need to start an external process
How Do I Use It?
The MacroScript SDK ships with both an ActiveX and native DLL interface so is compatible with the majority of development environments and languages. A basic set of methods provides access to the functionality and examples are included for VB, VBScript, C++, C# and Delphi.
Here’s a simple example in VB:
Set MacroScript = CreateObject("MScript.MacroScript") MacroScript.Init 'Run notepad and send some text to it MacroScript.RunCode "Run>notepad.exe" MacroScript.RunCode "WaitWindowOpen>Untitled - Notepad" MacroScript.RunCode "Send>Hello World" 'set variable x to the value entered in Text1 multiplied by 5 MacroScript.RunCode "Let>x=" & Text1.Text & "*5" 'get the value of x and put it in Text2 Text2.Text = "x=" & MacroScript.GetVar("x") MacroScript.Cleanup
In the above example first we demonstrate running some code to start Notepad and send text to it. Next we create a MacroScript variable set to the value supplied in a text box on the form multiplied by 5 and then demonstrate how we can retrieve values back from the script.
As well as run script code you can also run script files and pass parameters into code blocks and scripts as you would command line parameters for regular scripts. In addition the ActiveX has script and parms properties and a Run method for an easy way to apply a script and run it.
For more information click here; download the evaluation which includes full documentation and examples; or read a case study on how DM Software makes use of the SDK in their Healthcare Application.