How to make Macro Scheduler run macros in response to HTTP requests

Want to trigger a Macro Scheduler macro on another machine via PHP, Python, Javascript or language of your choice? You might have a user facing kiosk app running on android that needs to trigger some automation of a legacy Windows app, or perhaps you have a web app written in Javascript and running in the cloud, where an admin function needs to invoke some Windows UI automation. Here's how to do it.

Setup and Test with msNetGui

We need to make Macro Scheduler listen for HTTP requests. We can do this using the Remote Controller add-in which ships with the Enterprise Pack. The steps below walk through installing, configuring and testing the Remote Controller with Macro Scheduler running on your local machine.

  1. First install the msNet Remote Controller package which ships with Enterprise Pack.
  2. In the msNet program folder locate ServerSetup.exe. Run this on your local machine and install into the Macro Scheduler program folder as prompted.
  3. When asked for a port number enter something that is not already being used. E.g. 2222. You can leave password blank for now.
  4. Restart Macro Scheduler.
  5. Create a simple macro to test with and save it as 'remoteTest1':

    MessageModal>%fname% %sname%
    Let>MACRO_RESULT=<p>hello %fname% %sname
  6. Now let's first test with msNetGui.exe - which you'll find in the msNet program folder.

    Enter 127.0.0.1 in address, 2222 in Port Number, the macro name 'remoteTest1' or whatever you called the above macro. In Parameters enter /fname=fred /sname=bloggs:
    Hit Run and switch back to Macro Scheduler. You should see that the macro is running and a message has appeared saying "Fred Bloggs". Close that message and switch back and you should now see <p>hello Fred Bloggs</p> in the Result pane.

    Note how we are passing values to the variables fname and sname.

    If you get a connection error and you're running on your local machine with 127.0.0.1 then the most likely issue is that the port number is not available or your firewall is blocking Macro Scheduler. Try running ServerSetup again and try a different port number, check your firewall and make sure you're installing into your Macro Scheduler program folder and restarting Macro Scheduler afterwards.

Creating an HTTP Get Request

msNetGui.exe is just creating an HTTP GET request behind the scenes. We can do exactly the same with a web browser. Open up your favourite web browser and enter the following in the address bar:
http://127.0.0.1:2222/remoteTest1?fname=Fred&sname=Bloggs

Hit enter and switch back to Macro Scheduler and you should see the macro is running. Confirm the message box and switch back to your browser and you should see the html appear in the browser.  Note how we are setting the variable values via query string parameters.

Hopefully you can now see how you could trigger this macro from a language such as Javascript or Python, or even another Macro Scheduler macro. To do it from another Macro Scheduler macro the code would be as simple as:

HTTPRequest>http://127.0.0.1:2222/remoteTest1?fname=Fred&sname=Bloggs,,GET,,result

However, you probably want to get rid of that modal message box. In a real world scenario it is unlikely you'd want something waiting for user input and blocking the process from continuing. We just put that in there so that we could see something happening during testing. Also, of course, you would usually have the macro running on a different machine, so would be referencing a different IP address. When you do that you'll want to make sure the IP address is reachable and the port is unblocked for TCP traffic in the firewall.

Other language examples


Python:

import requests
response = requests.get("http://IP_ADDRESS:2222/remoteTest1?fname=Fred&sname=Bloggs")
print(response.content)

PHP:

$response = file_get_contents("http://IP_ADDRESS:2222/remoteTest1?fname=Fred&sname=Bloggs");
echo $response;

Javascript:

fetch('http://IP_ADDRESS:2222/test1?fname=fred&sname=bloggs').then(function(response) {console.log(response)})

Still need help? Contact Us Contact Us