Enhanced Replace operation to go back to originally active segment

This script will take the user back to the segment where the Replace operation was initiated, instead of to the last segment where the Replace operation was executed, which is Studio's default behavior.

The script works by inserting some placeholder text ("markerhere") in the original segment to be found and deleted at the end of the Replace operation.

Hotkeys to run the script:

Ctrl+H - Adds "markerhere" to the active segment. Opens the Replace window. If some text is selected, it will be pasted into the "Find what" field in the Find and Replace dialog box.

Enter - Runs the "Replace all" operation, no need to click Find Next and then Replace All.

Esc - Finds and deletes the "markerhere" placeholder text, leaving the user at the originally active segment, and closes the Find and Replace dialog box.

 

#IfWinActive ahk_exe SDLTradosStudio.exe
$^h::
Send ^c
Sleep 200
Send ^a{right}
Sleep 200
Send {Space}markerhere
Sleep 100
Send ^{PgUp}
KeyWait, h
send ^h
Sleep 200
Send ^v
Sleep 100
Send {tab}
return


#IfWinActive, Find and Replace, &Find what:
Enter::
Controlclick, Find &Next, Find and Replace
Sleep 1000
Controlclick, R&eplace All, Find and Replace
Return

Esc::
WinActivate, Find and Replace
Sendinput {Space}markerhere
Sleep 200
Sendinput {tab}
Sleep 200
Sendinput {delete}
Sleep 200
Controlclick, Find &Next, Find and Replace
Sleep 1000
Controlclick, R&eplace All, Find and Replace
Sleep 500
Controlclick, &Close, Find and Replace
Sleep 200
Return
#IfWinActive

 

Parents
  • Hi everyone,

    Hope somebody can help me. Since I updated to a new version of Trados, this brilliant script does not seem to work as well as it used to. The ESC key does not delete markerhere, does not make me come back to the original segment and a dialog box from Trados shows: Find complete:no more matches found. I have to click on ok to close that window and click again to close the Search and Replace dialog. Any idea?

    emoji
  •  

    I believe that the following edited script will work on Trados Studio 2021, 17.1.8.17828. Tested a couple of times. Added/deleted lines have been commented:

    #IfWinActive ahk_exe SDLTradosStudio.exe

    $^h::

    Send ^c

    Sleep 200

    Send ^a{right}

    Sleep 200

    Send {Space}markerhere

    Sleep 100

    Send ^{PgUp}

    KeyWait, h

    send ^h

    Sleep 200

    Send !f ; added line Trados 2022 SR1 to focus on the Find what field

    Sleep 100

    Send ^v

    Sleep 100

    Send {tab}

    return

     

     

    #IfWinActive, Find and Replace, &Find what:

    Enter::

    Controlclick, Find &Next, Find and Replace

    Sleep 1000

    Controlclick, R&eplace All, Find and Replace

    Return

     

    Esc::

    WinActivate, Find and Replace

    Sendinput {Space}markerhere

    Sleep 200

    Sendinput {tab}

    Sleep 200

    Sendinput {delete}

    Sleep 200

    Controlclick, Find &Next, Find and Replace

    Sleep 1000

    Controlclick, R&eplace All, Find and Replace

    ; Controlclick, &Replace, Find and Replace

     

    WinWaitActive, Information,,4 ; added line Trados 2022 SR1. Wait 4 seconds max. for the Information dialog box to open

    if !ErrorLevel ; added line Trados 2022 SR1. If Information dialog box is opened

          Send, {Enter} ; added line Trados 2022 SR1. Click on the OK button

    Controlclick, &Close, Find and Replace

    ; deleted line

    Return

    #IfWinActive

    emoji
Reply
  •  

    I believe that the following edited script will work on Trados Studio 2021, 17.1.8.17828. Tested a couple of times. Added/deleted lines have been commented:

    #IfWinActive ahk_exe SDLTradosStudio.exe

    $^h::

    Send ^c

    Sleep 200

    Send ^a{right}

    Sleep 200

    Send {Space}markerhere

    Sleep 100

    Send ^{PgUp}

    KeyWait, h

    send ^h

    Sleep 200

    Send !f ; added line Trados 2022 SR1 to focus on the Find what field

    Sleep 100

    Send ^v

    Sleep 100

    Send {tab}

    return

     

     

    #IfWinActive, Find and Replace, &Find what:

    Enter::

    Controlclick, Find &Next, Find and Replace

    Sleep 1000

    Controlclick, R&eplace All, Find and Replace

    Return

     

    Esc::

    WinActivate, Find and Replace

    Sendinput {Space}markerhere

    Sleep 200

    Sendinput {tab}

    Sleep 200

    Sendinput {delete}

    Sleep 200

    Controlclick, Find &Next, Find and Replace

    Sleep 1000

    Controlclick, R&eplace All, Find and Replace

    ; Controlclick, &Replace, Find and Replace

     

    WinWaitActive, Information,,4 ; added line Trados 2022 SR1. Wait 4 seconds max. for the Information dialog box to open

    if !ErrorLevel ; added line Trados 2022 SR1. If Information dialog box is opened

          Send, {Enter} ; added line Trados 2022 SR1. Click on the OK button

    Controlclick, &Close, Find and Replace

    ; deleted line

    Return

    #IfWinActive

    emoji
Children