Jump to content
Macro Express Forums
MakaPakaTobyHannah

Passing variables between Macro Express and AutoIT

Recommended Posts

This may be very simple, but that's never stopped me from not being able to figure things out.

 

I'm doing a bit more now with embedding AutoIT scripts as "External Scripts" into my macros, mostly for building more sophisticated GUIs.

 

My question is: how do you pass the values of variables OUT of the AutoIT script portion into Macro Express? Passing Macro Express variables INTO the AutoIT script portion is easy, of course. But I can't figure out an easy way to do the reverse.

 

The way I've been doing it is by copying an AutoIT variable to the clipboard, and upon completion of the AutoIT portion assigning a new variable in the Macro Express macro from the clipboard. That seems very clumsy. Also, it's a bit of a problem if the AutoIT script portion references multiple variables, possibly of different types. I'd have to concatenate all those variables into one string, for instance, with some separator characters, such as $^$^ (something like that), then in Macro Express get the variable as a string from the clipboard, split the string at the separator characters, convert types (some portion of it may need to be an integer or a decimal), blabla. That all seems very daft...

 

What am I missing?

 

I thought that the %console% variable might help; alas, it doesn't. The help file explains:

 

>>

Save Console Output To:

This function saves the output from the script to a text string variable and is only used if the output is sent to one of the console screens.

<<

 

I don't even know what that means. Which console screens? I know what a console screen is (at least I thought I did), but I just don't understand what that means, and why the console output variable is required.

 

So... maybe this is a two-part question: 1) how to pass variables out of the AutoIT script portion into Macro Express; and 2) what is the purpose and use of the required console output variable.

 

Thank you! Each time I post on this forum, I learn new things, and have always received solutions, or enough feedback to help me come up with a solution...

Share this post


Link to post
Share on other sites

Here's a 3-line example of passing in variable %T[1]% to AutoIt, and returning variable %T[2]% from AutoIt. Note that you can pass in multiple variables to AutoIt, but can receive only one parameter back (that console output variable you alluded to). Of course, you can receive from AutoIt the one variable in as complex a format as you like, e.g. a/b/c/d/e/f/g which could be converted into 7 different values in MEP.

Variable Set String %T[1]% to ""Input Parameter""
External Script: AutoIt
Text Box Display:

<VARIABLE SET STRING Option="\x00" Destination="%T[1]%" Value="\"Input Parameter\""/>
<EXTERNAL SCRIPT Language="AutoIt" Dest="%T[2]%" Script="msgbox(0,\"My Title\",\"My Text\")\r\nConsoleWrite(\"Returned Value is \" & $CmdLine[1])\r\n\r\n" Parameters="%T[1]%"/>
<TEXT BOX DISPLAY Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang3081{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 Passed in:%T[1]%\r\n\\par Returned:%T[2]%\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>

Share this post


Link to post
Share on other sites

I prefer to use the registry for things like this. The registry is quick given it's a loaded and available database.

Share this post


Link to post
Share on other sites

You can return multiple values from an external script, such as AutoIt, by having the external script save the information in a location where Macro Express Pro can read it. Save information into an text macro, an INI file, a text file or, as Cory suggests, the registry.

 

The July 7, 2011 issue of the Macro Express News http://www.macros.com/newsletters/MENewsJul2011.htm contains information about the External Script command.

 

There are sample external scripts in the External Scripts sample macro file: http://www.macros.com/usermacs/umexternalscripts.htm

 

You can see the technique of saving information into a text macro with the Multiple Inputs sample macro file: http://www.macros.com/usermacs/ummultipleinputs.htm.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×