Marking "Find and Replace" checkboxes as checked.

I am trying to write an Autohotkey 2.0 script that opens the "Find and Replace" window and marks two checkboxes as checked:

    WinActivate "Trados Studio - "
    WinWaitActive "Trados Studio - ", , 4
    Send("^f")
    WinWaitActive "Find and Replace", , 4
    ControlSetChecked 1, "&Match case", "Find and Replace"
    ControlSetChecked 1, "M&atch whole word", "Find and Replace"
    ControlSetChecked 1, "&Target", "Find and Replace"


The first time when I run it, it works great. But second time the checkboxes get unchecked. Does anyone have an idea what could be the problem?

emoji
  •  

    Untested (AI Solution) but...

    ControlSetChecked "&Match case", 1, "Find and Replace"
    ControlSetChecked "M&atch whole word", 1, "Find and Replace"
    ControlSetChecked "&Target", 1, "Find and Replace"

    In AutoHotkey v2.0, ControlSetChecked expects the control identifier first, then the checked state value, then the window title.  By putting 1 first and the control name second, AutoHotkey is interpreting the control name as a non-numeric checked value, which causes it to toggle instead of explicitly setting the state.

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

    emoji
  • Thanks, but according to Autohotkey 2.0 documentation, the command syntax is:
    ControlSetChecked NewSetting, Control , WinTitle

    Changing the order results in an error message.

    emoji
  •  

    Just goes to show AI isn't right for everything!!  Maybe something in this will be helpful?

    Given that your syntax is correct, the issue is likely that ControlSetChecked with value 1 is somehow toggling rather than explicitly setting the checkbox state. This could happen if:

    1. The control isn't being properly identified - The "&Match case" text might not be consistently recognized
    2. Trados Studio has custom checkbox behavior - Some applications implement non-standard checkbox controls

    Here are better solutions:

    Solution 1: Check the current state first

    WinActivate "Trados Studio - "
    WinWaitActive "Trados Studio - ", , 4
    Send("^f")
    WinWaitActive "Find and Replace", , 4
    
    ; Only check if currently unchecked
    if !ControlGetChecked("&Match case", "Find and Replace")
        ControlSetChecked(1, "&Match case", "Find and Replace")
    
    if !ControlGetChecked("M&atch whole word", "Find and Replace")
        ControlSetChecked(1, "M&atch whole word", "Find and Replace")
    
    if !ControlGetChecked("&Target", "Find and Replace")
        ControlSetChecked(1, "&Target", "Find and Replace")

    Solution 2: Use ClassNN identifiers instead Use Window Spy to get the actual ClassNN of each checkbox (like Button1, Button2, etc.):

    ControlSetChecked 1, "Button1", "Find and Replace"  ; Replace with actual ClassNN
    ControlSetChecked 1, "Button2", "Find and Replace"
    ControlSetChecked 1, "Button3", "Find and Replace"

    Solution 3: Force uncheck then check

    ; Force uncheck first
    ControlSetChecked 0, "&Match case", "Find and Replace"
    ControlSetChecked 0, "M&atch whole word", "Find and Replace"
    ControlSetChecked 0, "&Target", "Find and Replace"
    Sleep(50)
    ; Then check
    ControlSetChecked 1, "&Match case", "Find and Replace"
    ControlSetChecked 1, "M&atch whole word", "Find and Replace"
    ControlSetChecked 1, "&Target", "Find and Replace"

    The most reliable approach is probably Solution 1 or getting the proper ClassNN identifiers with Window Spy for Solution 2.

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

    emoji
  • None of these solutions worked, it's still a toggle.
    With solution 3, due to Sleep(50) it was visible how on first use, the script added the checkmarks, and on the second use removed them.

    emoji