Jump to content
Macro Express Forums
acantor

Challenge: Fix an Inconsistency in the Macro Express Script Editor

Recommended Posts

In the Macro Express Pro Script Editor, ten different "Variable Set" commands are available. The most frequently accessed of these are probably "Variable Set Integer" and "Variable Set String."

 

You may have noticed minor inconsistencies when different "Variable Set…" windows open:

 

- When "Variable Set From Misc" and "Variable Set Handle" opens, the first field has focus. (This is good!)

 

- When most "Variable Set…" windows open, you must press Tab to get to the first field.

 

- But when "Variable Set String" opens, you must press Tab five times to get to the first field.

 

The challenge:

 

Change the behaviour of Macro Express. When any "Variable Set…" window opens, the first field automatically has keyboard focus.

 

In other words, your macro solution will make it possible to immediately interact with the first field in these windows without the need to click the mouse or press the Tab key:

 

image.png.c1ea3faa22d678023ccc87b46b6a0c89.png

 

Bonus: If the first field in a "Variable Set..." window is a drop-down list, your macro opens the drop-down list. Hint: Hotkeys to do this include Alt + Up, Alt + Down, and F4.

Share this post


Link to post
Share on other sites

 

This appears to work although I had some erratic behaviour. Decimal played hard to get but fiddling around with delays appears to have sorted it. Bool is very slow to display. My code is just plain stuff, slogging through the IFs and could no doubt be improved.

 

Also I haven't figured out why I need to double click twice in the command list to get the dialog.

 

EDIT: Activation is

Window Title: Variable Set
Window Gains Focus
Title is a partial match

 

(Coudn't get reliable triggering with  Window Is Opened.)

 

Whether I'll actually now use this macro is uncertain 😉

 

// Assumes that one of the Variable Set... dialogs has just been opened
Wait for Window Title: Variable Set 
Variable Set String %tTitle% to topmost window title
 
// BOOL
If Variable %tTitle% Equals "Variable Set Bool"
  Text Type (Simulate Keystrokes): <TAB> // First a single tab
  Wait for Text Playback
  Delay: 0.1 seconds
  Text Type (Simulate Keystrokes): <F4> // Open drop-down
  Wait for Text Playback
  Delay: 0.1 seconds
End If
 
// CONTROL TEXT
If Variable %tTitle% Equals "Variable Set Control Text"
  Text Type (Simulate Keystrokes): <TAB>
  Delay: 0.1 seconds
  Text Type (Simulate Keystrokes): <F4> // Opens drop-down
  Delay: 0.1 seconds
End If
 
// DECIMAL
If Variable %tTitle% Equals "Variable Set Decimal"
  Text Type (Simulate Keystrokes): <TAB>
  Delay: 0.2 seconds
  Text Type (Simulate Keystrokes): <F4> // Opens drop-down
  Delay: 0.1 seconds
End If
 
// FROM FILE
If Variable %tTitle% Equals "Variable Set From File"
  Text Type (Simulate Keystrokes): <TAB>
  Delay: 0.1 seconds
  Text Type (Simulate Keystrokes): <F4>
  Delay: 0.1 seconds
End If
 
// HANDLE
If Variable %tTitle% Equals "Variable Set Handle"
// Back with Shift+Tab
  Text Type (Simulate Keystrokes): <F4> // Open drop-down
  Delay: 0.1 seconds
End If
 
// INTEGER
If Variable %tTitle% Equals "Variable Set Integer"
  Text Type (Simulate Keystrokes): <TAB>
  Delay: 0.1 seconds
  Text Type (Simulate Keystrokes): <F4> // Opens drop-down
  Delay: 0.1 seconds
End If
 
// STRING
If Variable %tTitle% Equals "Variable Set String"
  Text Type (Simulate Keystrokes): <TAB><TAB><TAB><TAB><TAB>
  Delay: 0.1 seconds
  Text Type (Simulate Keystrokes): <F4> // Opens drop-down
  Delay: 0.1 seconds
End If
 
// ASCII CHAR
If Variable %tTitle% Equals "Variable Set to ASCII Char"
  Text Type (Simulate Keystrokes): <TAB>
  Delay: 0.1 seconds
End If
 
// ASCII VALUE
If Variable %tTitle% Equals "Variable Set to ASCII Value"
  Text Type (Simulate Keystrokes): <TAB>
  Delay: 0.1 seconds
End If
 
// MISC
// As it's not one of the preceding nine, the dialog opened must be 'Variable Set From Misc'
// No tabs needed, and no drop-down.
<COMMENT Value="Assumes that one of the Variable Set... dialogs has just been opened"/>
<WAIT FOR WINDOW TITLE Title="Variable Set " Partial="TRUE" Wildcards="FALSE" Indefinite="TRUE" Hours="0" Minutes="0" Seconds="0"/>
<VARIABLE SET STRING Option="\x05" Destination="%tTitle%"/>
<COMMENT/>
<COMMENT Value="BOOL"/>
<IF VARIABLE Variable="%tTitle%" Condition="\x00" Value="Variable Set Bool" IgnoreCase="TRUE"/>
<TEXT TYPE Action="0" Text="<TAB>" _COMMENT="First a single tab"/>
<WAIT FOR TEXT PLAYBACK Indefinite="TRUE" Hours="0" Minutes="0" Seconds="0"/>
<DELAY Flags="\x01" Time="0.1"/>
<TEXT TYPE Action="0" Text="<F4>" _COMMENT="Open drop-down"/>
<WAIT FOR TEXT PLAYBACK Indefinite="TRUE" Hours="0" Minutes="0" Seconds="0"/>
<DELAY Flags="\x01" Time="0.1"/>
<END IF/>
<COMMENT/>
<COMMENT Value="CONTROL TEXT"/>
<IF VARIABLE Variable="%tTitle%" Condition="\x00" Value="Variable Set Control Text" IgnoreCase="FALSE"/>
<TEXT TYPE Action="0" Text="<TAB>"/>
<DELAY Flags="\x01" Time="0.1"/>
<TEXT TYPE Action="0" Text="<F4>" _COMMENT="Opens drop-down"/>
<DELAY Flags="\x01" Time="0.1"/>
<END IF/>
<COMMENT/>
<COMMENT Value="DECIMAL"/>
<IF VARIABLE Variable="%tTitle%" Condition="\x00" Value="Variable Set Decimal" IgnoreCase="FALSE"/>
<TEXT TYPE Action="0" Text="<TAB>"/>
<DELAY Flags="\x01" Time="0.2"/>
<TEXT TYPE Action="0" Text="<F4>" _COMMENT="Opens drop-down"/>
<DELAY Flags="\x01" Time="0.1"/>
<END IF/>
<COMMENT/>
<COMMENT Value="FROM FILE"/>
<IF VARIABLE Variable="%tTitle%" Condition="\x00" Value="Variable Set From File" IgnoreCase="FALSE"/>
<TEXT TYPE Action="0" Text="<TAB>"/>
<DELAY Flags="\x01" Time="0.1"/>
<TEXT TYPE Action="0" Text="<F4>"/>
<DELAY Flags="\x01" Time="0.1"/>
<END IF/>
<COMMENT/>
<COMMENT Value="HANDLE"/>
<IF VARIABLE Variable="%tTitle%" Condition="\x00" Value="Variable Set Handle" IgnoreCase="FALSE"/>
<COMMENT Value="Back with Shift+Tab"/>
<TEXT TYPE Action="0" Text="<F4>" _COMMENT="Open drop-down"/>
<DELAY Flags="\x01" Time="0.1"/>
<END IF/>
<COMMENT/>
<COMMENT Value="INTEGER"/>
<IF VARIABLE Variable="%tTitle%" Condition="\x00" Value="Variable Set Integer" IgnoreCase="FALSE"/>
<TEXT TYPE Action="0" Text="<TAB>"/>
<DELAY Flags="\x01" Time="0.1"/>
<TEXT TYPE Action="0" Text="<F4>" _COMMENT="Opens drop-down"/>
<DELAY Flags="\x01" Time="0.1"/>
<END IF/>
<COMMENT/>
<COMMENT Value="STRING"/>
<IF VARIABLE Variable="%tTitle%" Condition="\x00" Value="Variable Set String" IgnoreCase="FALSE"/>
<TEXT TYPE Action="0" Text="<TAB><TAB><TAB><TAB><TAB>"/>
<DELAY Flags="\x01" Time="0.1"/>
<TEXT TYPE Action="0" Text="<F4>" _COMMENT="Opens drop-down"/>
<DELAY Flags="\x01" Time="0.1"/>
<END IF/>
<COMMENT/>
<COMMENT Value="ASCII CHAR"/>
<IF VARIABLE Variable="%tTitle%" Condition="\x00" Value="Variable Set to ASCII Char" IgnoreCase="FALSE"/>
<TEXT TYPE Action="0" Text="<TAB>"/>
<DELAY Flags="\x01" Time="0.1"/>
<END IF/>
<COMMENT/>
<COMMENT Value="ASCII VALUE"/>
<IF VARIABLE Variable="%tTitle%" Condition="\x00" Value="Variable Set to ASCII Value" IgnoreCase="FALSE"/>
<TEXT TYPE Action="0" Text="<TAB>"/>
<DELAY Flags="\x01" Time="0.1"/>
<END IF/>
<COMMENT/>
<COMMENT Value="MISC"/>
<COMMENT Value="As it's not one of the preceding nine, the dialog opened must be 'Variable Set From Misc'"/>
<COMMENT Value="No tabs needed, and no drop-down."/>

 

Share this post


Link to post
Share on other sites

I can see where this is useful when coding macros, and makes for one less irritation.  I do little enough development these days that the irritation is good to keep me alert. 

What I never thought about before, however, is that every command window appears focused with its own name and therefore can trigger a macro to run.  I will keep that in mind for the future -- it could be handy for tasks other than ironing out inconsistencies.  As usual with your challenges, I learned something new even if I didn't write a macro. 

Share this post


Link to post
Share on other sites
11 hours ago, rberq said:

What I never thought about before, however, is that every command window appears focused with its own name and therefore can trigger a macro to run.

 

This appears to be generally true with Macro Express command windows, but there may be exceptions.

 

After posting this challenge, I decided to apply what I had learned in crafting a solution to the "Set Variable... " issue to handle another, similar situation... and so far, I have made zero progress with a particular class of command windows. I haven't given up yet. I'm still experimenting.

 

In the next day or so, I’ll post my solution to the "Set Variable…" challenge – which includes a kludgy workaround that I’m almost embarrassed to share. I'm still trying to figure out why a workaround is needed at all. I don't think Terry experienced the problem I am seeing!

Share this post


Link to post
Share on other sites
10 hours ago, acantor said:

I'm still trying to figure out why a workaround is needed at all. I don't think Terry experienced the problem I am seeing!

What version of ME are you using?  You said above, "... when "Variable Set String" opens, you must press Tab five times to get to the first field."  Using a macro to insert commands (inspired by your other challenge), I believe I had to TAB only twice.  Odd. 

Share this post


Link to post
Share on other sites
55 minutes ago, rberq said:

What version of ME are you using? 

 

Version 6.1.3.something.

 

I have had to press Tab five times for a long time, but I'm not sure how long. Perhaps several months, and perhaps years. The inconsistencies in the "Set Variable..." windows that gave rise to this challenge might be relatively new, or only occur in newer versions.

 

I have filed a bug report with Insight Software, noting that when Set Variable... windows open, either the first field has focus (the desired behaviour), or the user must give the first field focus by pressing Tab between one and five times.

 

In the meantime, I'm good with our DIY fixes!

Share this post


Link to post
Share on other sites

Here are my solution to this challenge. For reasons I cannot understand, I needed two macros when one should be enough:

 

1. One script recognizes all windows with "Variable Set" in their titles, except, weirdly, when the title is "Variable Set Bool"

 

2. The second script specifically handles "Variable Set Bool" windows.

 

The first macro activates when windows containing "Variable Set" in their titles OPEN.

 

The second macro activates when windows that contain "Variable Set Bool" GAIN FOCUS. I would prefer these scripts to be triggered when windows open rather than gain focus, but I couldn’t figure out how do this with "Variable Set Bool".

 

Macro 1: General case for all "Variable Set…" windows, although for unknown reasons "Variable Set Bool" isn’t recognized:

 

Quote

// Purpose: Automatically give focus to the topmost field when "Variable Set..." windows open
// Known limitation: This macro fails to activate for "Variable Set Bool" windows. Workaround: a separate macro
// Activation: When "Variable Set" window is opened, NOT when it gains focus! (Partial match)
// Scope: "Macro Express Pro - Script Editor". Uncheck "A window with this title must be on top" (Partial match)
// Note: This macro doesn't handle "Variable Set from Misc" window because its first field has focus by default
 
Variable Set String %WinTitle% to topmost window title
 
// Tab five times for "Variable Set String" dialog box
If Variable %WinTitle% Equals "Variable Set String"
  Text Type (Simulate Keystrokes): <TAB><TAB><TAB><TAB><TAB>
  Text Type (Simulate Keystrokes): <F4> // Drop the list
End If
 
// Tab once for most "Variable Set..." dialog boxes
If Variable %WinTitle% Equals "Variable Set Bool" // Not working. Use a separate script for "Set Variable Bool"!
  OR
If Variable %WinTitle% Equals "Variable Set Control Text"
  OR
If Variable %WinTitle% Equals "Variable Set Decimal"
  OR
If Variable %WinTitle% Equals "Variable Set Integer"
  OR
If Variable %WinTitle% Equals "Variable Set From File"
  OR
If Variable %WinTitle% Contains "Variable Set to ASCII" // By using "Contains" instead of "Equals" both "Set to ASCII" windows are handled
  Text Type (Simulate Keystrokes): <TAB>
  Text Type (Simulate Keystrokes): <F4> // Drop the list
End If
 
// No tabbing needed for "Variable Set Handle" window. Just drop the list
If Variable %WinTitle% Equals "Variable Set Handle"
  Text Type (Simulate Keystrokes): <F4> // Drop the list
End If

 

<COMMENT Value="Purpose: Automatically give focus to the topmost field when \"Variable Set...\" windows open" _BACK="0080FFFF"/>
<COMMENT Value="Known limitation: This macro fails to activate for \"Variable Set Bool\" windows. Workaround: a separate macro" _BACK="0080FFFF"/>
<COMMENT Value="Activation: When \"Variable Set\" window is opened, NOT when it gains focus! (Partial match)" _BACK="0080FFFF"/>
<COMMENT Value="Scope: \"Macro Express Pro - Script Editor\". Uncheck \"A window with this title must be on top\" (Partial match)" _BACK="0080FFFF"/>
<COMMENT Value="Note: This macro doesn't handle \"Variable Set from Misc\" window because its first field has focus by default" _BACK="0080FFFF"/>
<COMMENT/>
<VARIABLE SET STRING Option="\x05" Destination="%WinTitle%"/>
<COMMENT/>
<COMMENT Value="Tab five times for \"Variable Set String\" dialog box" _BACK="0080FFFF"/>
<IF VARIABLE Variable="%WinTitle%" Condition="\x00" Value="Variable Set String" IgnoreCase="FALSE"/>
<TEXT TYPE Action="0" Text="<TAB><TAB><TAB><TAB><TAB>"/>
<TEXT TYPE Action="0" Text="<F4>" _COMMENT="Drop the list"/>
<END IF/>
<COMMENT/>
<COMMENT Value="Tab once for most \"Variable Set...\" dialog boxes" _BACK="0080FFFF"/>
<IF VARIABLE Variable="%WinTitle%" Condition="\x00" Value="Variable Set Bool" IgnoreCase="FALSE" _COMMENT="Not working. Use a separate script for \"Variable Set Bool\"!"/>
<OR/>
<IF VARIABLE Variable="%WinTitle%" Condition="\x00" Value="Variable Set Control Text" IgnoreCase="FALSE"/>
<OR/>
<IF VARIABLE Variable="%WinTitle%" Condition="\x00" Value="Variable Set Decimal" IgnoreCase="FALSE"/>
<OR/>
<IF VARIABLE Variable="%WinTitle%" Condition="\x00" Value="Variable Set Integer" IgnoreCase="FALSE"/>
<OR/>
<IF VARIABLE Variable="%WinTitle%" Condition="\x00" Value="Variable Set From File" IgnoreCase="FALSE"/>
<OR/>
<IF VARIABLE Variable="%WinTitle%" Condition="\x06" Value="Variable Set to ASCII" IgnoreCase="FALSE" _COMMENT="By using \"Contains\" instead of \"Equals\" both \"Set to ASCII\" windows are handled"/>
<TEXT TYPE Action="0" Text="<TAB>"/>
<TEXT TYPE Action="0" Text="<F4>" _COMMENT="Drop the list"/>
<END IF/>
<COMMENT/>
<COMMENT Value="No tabbing needed for \"Variable Set Handle\" window. Just drop the list" _BACK="0080FFFF"/>
<IF VARIABLE Variable="%WinTitle%" Condition="\x00" Value="Variable Set Handle" IgnoreCase="FALSE"/>
<TEXT TYPE Action="0" Text="<F4>" _COMMENT="Drop the list"/>
<END IF/>

 

Macro 2: Special case for "Variable Set Bool" windows:

 

Quote

// Purpose: Automatically give focus to the topmost field when "Variable Set Bool" windows open
// This is a special case. Another script handles all other "Variable Set..." windows
// Activation: When "Variable Set Bool" (partial match) window gains focus, but not when it opens!
// Scope: "Macro Express Pro - Script Editor" (Partial match; Uncheck "A window with this title must be on top")
 
Text Type (Simulate Keystrokes): <TAB>
Text Type (Simulate Keystrokes): <ALT><UP ARROW>

 

<COMMENT Value="Purpose: Automatically give focus to the topmost field when \"Variable Set Bool\" windows open" _BACK="0080FFFF"/>
<COMMENT Value="This is a special case. Another script handles all other \"Variable Set...\" windows" _BACK="0080FFFF"/>
<COMMENT Value="Activation: When \"Variable Set Bool\" (partial match) window gains focus, but not when it opens!" _BACK="0080FFFF"/>
<COMMENT Value="Scope: \"Macro Express Pro - Script Editor\" (Partial match; Uncheck \"A window with this title must be on top\")" _BACK="0080FFFF"/>
<COMMENT/>
<TEXT TYPE Action="0" Text="<TAB>"/>
<TEXT TYPE Action="0" Text="<ALT><UP ARROW>"/>

 

 

Share this post


Link to post
Share on other sites
1 hour ago, acantor said:

The second macro activates when windows that contain "Variable Set Bool" GAIN FOCUS. I would prefer these scripts to be triggered when windows open rather than gain focus, but I couldn’t figure out how do this with "Variable Set Bool".

Same behavior with ME Pro 4.9 and Windows 7.  Odd. 

Share this post


Link to post
Share on other sites

This sure is throwing up some strange behaviour!

 

My original macro, which I'm pretty sure I tested thoroughly, now fails for the following types: Decimal, Handle, ASCII Char and ASCII Value.

 

In every case it's because the macro does not get activated. (Note again that, unlike Alan, I can only get any success with Window Gains Focus.)

 

I tried changing the IF criterion to the width of the dialog, as the ten are unique. But that gave the same failures.

 

I tried changing the macro activation to Window Loses Focus from Macro Express Pro - Script Editor (Name of macro) which gave a different set of failures.

 

It seems those four culprit dialogs are Invisible to MX Pro in some way!

 

I'm even considering using the full command list (instead of my preferred Favourites) and activating the macro by mouse clicks in the relevant area of Macro Express Pro - Script Editor (Name of macro)...

 

 

Share this post


Link to post
Share on other sites

Terry,

 

I would be curious to know if my two macros work when you run them. If you do, attend closely to the settings I outlined in the comments for "Activation" and "Scope." I found the settings to be persnickety. No problem setting "Scope" to "Global."

Share this post


Link to post
Share on other sites
11 hours ago, acantor said:

Terry,

 

I would be curious to know if my two macros work when you run them. If you do, attend closely to the settings I outlined in the comments for "Activation" and "Scope." I found the settings to be persnickety. No problem setting "Scope" to "Global."

 

Second macro:

OK

 

First macro: with scope and activation same as yours:

Fails here except for ASCII Char and ASCII Val. However I suspect a timing issue because for the other eight types I found that the macro did run on about 10-15% of attempts. That was with the command selected followed by either a mouse left d-click or keyboard Enter, in either case followed by Esc to repeatedly try again. IOW the brisk sequence of Enter, Esc would occasionally result in your macro being run. The converse applied with the two ASCII types, which would occasionally fail.

 

First macro: with global scope and activation same as yours:

Fails here except for ASCII Char and ASCII Val. But I don't think it gave even that small proportion of successes with the other eight.

 

First macro: with global scope and activation Window Gains Focus (like my macro).

All work OK (except for Bool).

 

Terry, Wednesday 5 August 2020, 10:05 UK

 

 

 

 

Share this post


Link to post
Share on other sites

Terry,

 

Thank you for checking, and for making additional changes to my scripts.

 

1. My first thought is that differences we are observing are partially due to timing. I tend to use delays sparingly in my MEP scripts. When I'm building or debugging a script, I do pepper the code with delays. When I'm refining a script, I often find the delays are not necessary. Perhaps the need for pauses is a function of the speediness of the computer and/or the version of the operating system. My new Windows 10 machine (purchased a few months ago) has "only" 8 GB RAM, which in hindsight was not a wise decision. It's the pokiest computer I've owned in years. (I make extensive use of a RAM-intensive application, Dragon Professional.)

 

2. My second thought is that differences might be partially due to different Windows 10 settings. In an effort to squeeze the best performance from my new computer, I toggled OFF as many standard Windows 10 visual display settings as I could find. I wonder whether turning off gratuitous visual effects might be partially responsible for the differences. 

Share this post


Link to post
Share on other sites

Something related to try as we puzzle out the circumstances that lead scripts to be recognized when triggered by windows that open vs. windows that gain focus.

 

Create ONE macro that is triggered by the opening of any of the five "Variable Modify" windows.


The scope for mine is program-specific: "macscript.exe" (the program only needs to be running. My script fails when the executable must be on the top).

 

The activation for mine is window-specific: "Variable Modify " -- note the space after the word "Modify". Window is opened, partial match, no wildcards.

 

Here is the script:

 

Quote

Text Type (Simulate Keystrokes): <TAB> // Move focus to the drop-down list
Text Type (Simulate Keystrokes): <F4> // Drop the list

 

This script has been working reliably for me when the window OPENS. But what about for you? If nothing happens, change the trigger from window opens to window gains focus.

Share this post


Link to post
Share on other sites

Alan: Three of the four Variable Modify options work OK here with your macro, activation and scope. The exception is Date/Time, which fails to activate the macro.

 

The opposite happens if I switch activation to focus; only Date/Time then runs the macro!

 

I'm hoping Support might come in with some ideas?

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...