Jump to content
Macro Express Forums

Need help with finding a way to determine when a window is no longer running. Running into a bug?


Recommended Posts

Here is an example that opens the Text Type in Macro Express Script Editor. It seems to freeze after the Repeat Exit at the end of this example. Once the Text Type is open I would like to be able to manually open the Variables (Button) then close that window and be able to open the Misc Keys (button) then close that window and have the macro wait till the Text Type window closes. Just for simulation, you can manually close/cancel the Text Type Window. Then the macro should continue on to Repeat Exit and on to Text Box Display, but it freezes on multiple computers. Hopefully someone knows a better or different way to accomplish this. Command text version below too.

Thanks!

<COMMENT Value="Moves cusor over to command area"/>
<KEYSTROKE SPEED Delay="50"/>
<TEXT TYPE Action="0" Text="<ALTD><ARROW UP><ALTU>" _COMMENT="Moves cursor to the commands area under script"/>
<TEXT TYPE Action="0" Text="<HOME>"/>
<TEXT TYPE Action="0" Text="<ARROW DOWN><ARROW UP>" _COMMENT="Resets tree on \"All Commands\""/>
<TEXT TYPE Action="0" Text="<TAB>"/>
<KEYSTROKE SPEED Delay="0"/>
<COMMENT Value="End -Moves cusor over to command area"/>
<COMMENT Value="Text Type                                                                                                      Keyboard section"/>
<KEYSTROKE SPEED Delay="50"/>
<DELAY Flags="\x01" Time="0.3"/>
<TEXT TYPE Action="0" Text="k"/>
<DELAY Flags="\x01" Time="0.3"/>
<TEXT TYPE Action="0" Text="<ARROW RIGHT>" _COMMENT="Opens menu"/>
<TEXT TYPE Action="0" Text="t"/>
<TEXT TYPE Action="0" Text="<ENTER>"/>
<DELAY Flags="\x01" Time="0.3"/>
<WAIT FOR WINDOW TITLE Title="Text Type" Partial="FALSE" Wildcards="FALSE" Indefinite="FALSE" Hours="0" Minutes="0" Seconds="2" _IGNORE="0x0014"/>
<DELAY Flags="\x01" Time="0.3"/>
<COMMENT Value="Problem area"/>
<VARIABLE SET STRING Option="\x05" Destination="%T[1]%"/>
<REPEAT START Start="1" Step="1" Count="50" Save="FALSE"/>
<IF WINDOW Option="\x01" Title="%T[1]%" Partial="TRUE" Wildcards="FALSE"/>
<WAIT FOR WINDOW TO LOSE FOCUS Title="%T[1]%" Partial="TRUE" Wildcards="FALSE" Indefinite="TRUE" Hours="0" Minutes="0" Seconds="0"/>
<DELAY Flags="\x01" Time=".1"/>
<VARIABLE SET STRING Option="\x05" Destination="%T[2]%"/>
<WAIT FOR WINDOW TO LOSE FOCUS Title="%T[2]%" Partial="TRUE" Wildcards="FALSE" Indefinite="TRUE" Hours="0" Minutes="0" Seconds="0"/>
<ELSE/>
<REPEAT EXIT/>
<END IF/>
<END REPEAT/>
<TEXT BOX DISPLAY Title="test 2" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 %T[1]% is no longer running.\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x01" Delay=".75"/>
<DELAY Flags="\x01" Time=".75"/>
// Moves cusor over to command area
Keystroke Speed: 50 milliseconds
Text Type (Simulate Keystrokes): <ALTD><ARROW UP><ALTU> // Moves cursor to the commands area under script
Text Type (Simulate Keystrokes): <HOME>
Text Type (Simulate Keystrokes): <ARROW DOWN><ARROW UP> // Resets tree on "All Commands"
Text Type (Simulate Keystrokes): <TAB>
Keystroke Speed: 0 milliseconds
// End -Moves cusor over to command area
// Text Type                                                                                                      Keyboard section
Keystroke Speed: 50 milliseconds
Delay: 0.3 seconds
Text Type (Simulate Keystrokes): k
Delay: 0.3 seconds
Text Type (Simulate Keystrokes): <ARROW RIGHT> // Opens menu
Text Type (Simulate Keystrokes): t
Text Type (Simulate Keystrokes): <ENTER>
Delay: 0.3 seconds
Wait for Window Title: Text Type
Delay: 0.3 seconds
// Problem area
Variable Set String %T[1]% to topmost window title
Repeat Start (Repeat 50 times)
  If Window "%T[1]%" is running
    Wait for Window to Lose Focus: %T[1]%
    Delay: .1 seconds
    Variable Set String %T[2]% to topmost window title
    Wait for Window to Lose Focus: %T[2]%
  Else
    Repeat Exit
  End If
End Repeat
Text Box Display: test 2
Delay: .75 seconds

 

Link to comment
Share on other sites

I did a little digging in the forum and found a couple of references to using Window Controls. To answer my own question, it seems like capturing the control was the answer. No matter how many ways I tried the wait for window and if window is running. It just does not work. It is mind boggling after awhile!

Here is the resulting code.

<COMMENT Value="Moves cusor over to command area"/>
<KEYSTROKE SPEED Delay="50"/>
<TEXT TYPE Action="0" Text="<ALTD><ARROW UP><ALTU>" _COMMENT="Moves cursor to the commands area under script"/>
<TEXT TYPE Action="0" Text="<HOME>"/>
<TEXT TYPE Action="0" Text="<ARROW DOWN><ARROW UP>" _COMMENT="Resets tree on \"All Commands\""/>
<TEXT TYPE Action="0" Text="<TAB>"/>
<KEYSTROKE SPEED Delay="0"/>
<COMMENT Value="End -Moves cusor over to command area"/>
<COMMENT Value="Text Type                                                                                                      Keyboard section"/>
<KEYSTROKE SPEED Delay="50"/>
<DELAY Flags="\x01" Time="0.3"/>
<TEXT TYPE Action="0" Text="k"/>
<DELAY Flags="\x01" Time="0.3"/>
<TEXT TYPE Action="0" Text="<ARROW RIGHT>" _COMMENT="Opens menu"/>
<TEXT TYPE Action="0" Text="t"/>
<TEXT TYPE Action="0" Text="<ENTER>"/>
<DELAY Flags="\x01" Time="0.3"/>
<WAIT FOR WINDOW TITLE Title="Text Type" Partial="FALSE" Wildcards="FALSE" Indefinite="FALSE" Hours="0" Minutes="0" Seconds="2" _IGNORE="0x0014"/>
<DELAY Flags="\x01" Time="0.3"/>
<CAPTURE CONTROL Option="\x01" Control="%C[1]%" UseText="FALSE"/>
<DELAY Flags="\x01" Time="0.3"/>
<WAIT FOR CONTROL Control="%C[1]%" Option="\x01" Indefinite="TRUE" Hours="0" Minutes="0" Seconds="0"/>
<IF CONTROL Option="\x02" Variable="%C[1]%"/>
<TEXT BOX DISPLAY Title="Testing 1" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 Yes still exists.\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="400" Height="350" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x01" Delay="1" _COMMENT="                              ***Testing"/>
<DELAY Flags="\x01" Time="1"/>
<ELSE/>
<TEXT BOX DISPLAY Title="Testing 1" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 No longer exists.\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="400" Height="350" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x01" Delay="1" _COMMENT="                              ***Testing"/>
<DELAY Flags="\x01" Time="1"/>
<END IF/>

 

Commands Text:

// Moves cusor over to command area
Keystroke Speed: 50 milliseconds
Text Type (Simulate Keystrokes): <ALTD><ARROW UP><ALTU> // Moves cursor to the commands area under script
Text Type (Simulate Keystrokes): <HOME>
Text Type (Simulate Keystrokes): <ARROW DOWN><ARROW UP> // Resets tree on "All Commands"
Text Type (Simulate Keystrokes): <TAB>
Keystroke Speed: 0 milliseconds
// End -Moves cusor over to command area
// Text Type                                                                                                      Keyboard section
Keystroke Speed: 50 milliseconds
Delay: 0.3 seconds
Text Type (Simulate Keystrokes): k
Delay: 0.3 seconds
Text Type (Simulate Keystrokes): <ARROW RIGHT> // Opens menu
Text Type (Simulate Keystrokes): t
Text Type (Simulate Keystrokes): <ENTER>
Delay: 0.3 seconds
Wait for Window Title: Text Type
Delay: 0.3 seconds
Capture Control from Focused Control into %C[1]%
Delay: 0.3 seconds
Wait for Control until %C[1]% "Does not Exist"
If Control "%C[1]%" Exists
  Text Box Display: Testing 1 //                               ***Testing
  Delay: 1 seconds
Else
  Text Box Display: Testing 1 //                               ***Testing
  Delay: 1 seconds
End If

 

Link to comment
Share on other sites

Quote

Once the Text Type is open I would like to be able to manually open the Variables (Button) then close that window and be able to open the Misc Keys (button) then close that window and have the macro wait till the Text Type window closes.

 

Not sure this is the best way to handle this. A macro that runs in the background waiting for something to happen is, in my experience, prone to failure because it interferes with, or prevents, other macros from running.

 

Perhaps this needs to be a sequence of two (or more) scripts instead of one.

 

What's good about your macro is that you've automated the opening of the Text Type dialog, and that's not easy! Kudos!

  • Like 1
Link to comment
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...