AutoHotKey script for choosing translaton suggestion from AI Assistant

Hei,

I have tried to write an AutoHotKey script for automatically replacing suggestions from OpenAi provider with suggestion from AI Assistant (keyboard shortcut Alt+W), confirm and go to the next segment. I wanted to automatize this process by pressing F9 key. It seems though that my script has some error, because what happens after applying F9 is that the translation from Open Ai is chosen anyway, not the suggestion from AI Assistant.

Do you have any suggestions what should be replaced in my script?

Thank you so much for your help in advance.

Screenshot of a translation software interface with two panels. The left panel shows text in Norwegian, and the right panel shows the translated text in Polish. There are annotations and suggestions from AI Assistant with highlighted terms and corresponding explanations at the bottom.

; AutoHotkey script to apply translation suggestion from AI Assistant,
; confirm the current segment, and move to the next segment in SDL Trados Studio

; Set a hotkey (e.g., F9) to trigger the commands
F9::
; Activate SDL Trados Studio window
WinActivate, ahk_exe TradosStudio2024_18.0.0.1013.exe ; Adjust the executable name if necessary

; Send the command to apply translation suggestion
; Replace with the actual shortcut you use to apply AI suggestion if needed
Send, ^a ; Assuming Alt+W applies the suggestion

; Confirm the current segment
Send, ^{Enter} ; Assuming Ctrl+Enter confirms the segment


return

   



Generated Image Alt-Text
[edited by: RWS Community AI at 12:56 PM (GMT 0) on 14 Nov 2024]
emoji
Parents
  •   

    Looking at the text in the comments it looks as though you may have copied this from somewhere else and tried to adapt.  I think the simplest approach is to simply write out what you need to happen... and in this case it appears to be this:

    1. insert the AI Assistant result - Alt+W according to your comment
    2. Switch focus back to the Editor ; F6 (I didn't set a shortcut for this it just worked)
    3. Confirm the segment - Ctrl+Enter

    That's it. Check these keystrokes work when you do it manually and if they do just string them together with a script to map them to your F9 key.

    I did this:

    ;------------------------------------------------------------------------------
    ; Insert the AI Assistant Translation Result and Confirm it
    ;------------------------------------------------------------------------------
    
    #Requires AutoHotkey v2.0
    
    F9::
    {
        ; Check if SDL Trados Studio is the active window
        if WinActive("ahk_exe SDLTradosStudio.exe") {
            ; Send Alt+W to apply translation suggestion
            Send("!w")
            
            ; Small delay to ensure the first command is processed
            Sleep(200)
            
            ; Send F6 to switch focus back to the Editor
            Send("F6")
            
            ; Another short delay to ensure focus change is applied
            Sleep(200)
            
            ; Send Ctrl+Enter to confirm translation
            Send("^Enter")
        }
    }

    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
  • Hello again,

    Unfortunately it did not work. On applying F9 it still does the same thing, that is confirms the current translation from Open AI and not inserting the suggestion from AI Assistant. It is so frustrating, I have tried in days and it wont work. Maybe something else is wrong in my settings? Or maybe Alt+W is linked to a wrong command?OR maybe the script should also include "Select the translation suggestion nr. 1" and THEN "Apply the translation suggestion" - something between Alt+W and F6? 

    Screenshot of Keyboard Shortcuts settings in Trados Copilot - AI Assistant showing a list of actions with their corresponding shortcuts. 'Apply Translation Suggestion' is set to Alt+W. No errors visible.

    Screenshot of keyboard shortcuts settings showing 'Apply Translation Result' mapped to Ctrl+F, 'Apply Translation Suggestion' to Alt+W, and 'Apply Translation without upLIFT Repair' to Ctrl+Alt+U.

    Screenshot of an AutoHotkey script editor with code for a script named 'Apply Suggestion-1.ahk'. The script includes a hotkey F9 to send Alt+W, a delay, F6, another delay, and Ctrl+Enter when SDL Trados Studio is active.

    emoji


    Generated Image Alt-Text
    [edited by: RWS Community AI at 11:22 AM (GMT 1) on 7 Oct 2024]
  •   

    Well... a couple of things I think:

    1. AI Assistant and OpenAI probably return the same thing.  They are not different resources (just making sure you know this?)
      • maybe the script should also include "Select the translation suggestion nr. 1" and THEN "Apply the translation suggestion"

      Quite possibly... depends on your prompt and what is being returned.  You didn't mention this at the start.

    I think you should do exactly as I asked you before.  First set out what you have to do manually and write down the sequence of keystrokes that work for you.  If you don't know this you have no chance of making this work consistently.

    Is there any way one can learn this on ones own?

    Yes... https://www.autohotkey.com/docs/v2/howto/RunExamples.htm

    There are many tutorials there and all of them will help you learn how to write your own scripts.

    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
  • Hello again,

    Thank you again for your help. 

    I have been trying different alternvatives today and the closest I get is this one:

    Now TS selects the right translation BUT does not confirm. Not able to find out why, because the part with confirming was working before, and now it is the other way round. All is working besides confirming. 

    Trados selects the right translation, waits a few seconds and sets "€nter" at the end of each sentence, instead of confirming. Do you have any idea why?

    F9::
    {
    if WinActive("ahk_exe SDLTradosStudio.exe") {
    ; Step 1: Send Escape to reset focus, if needed
    Send("{Esc}")

    ; Step 2: Send Alt+E to trigger AI Assistant (before refinement)
    Send("!e")

    ; Step 3: Wait longer for the refinement process to complete
    Sleep(5000) ; Adjust based on actual refinement time (increase delay if needed)

    ; Step 4: Manually reselect the refined suggestion
    Send("!e") ; Assuming Alt+E is still used to select refined suggestions

    ; Step 5: Wait briefly to ensure selection is processed
    Sleep(200)

    ; Step 6: Send Ctrl+Enter to confirm translation
    Send("^Enter")
    }
    }

    emoji
Reply
  • Hello again,

    Thank you again for your help. 

    I have been trying different alternvatives today and the closest I get is this one:

    Now TS selects the right translation BUT does not confirm. Not able to find out why, because the part with confirming was working before, and now it is the other way round. All is working besides confirming. 

    Trados selects the right translation, waits a few seconds and sets "€nter" at the end of each sentence, instead of confirming. Do you have any idea why?

    F9::
    {
    if WinActive("ahk_exe SDLTradosStudio.exe") {
    ; Step 1: Send Escape to reset focus, if needed
    Send("{Esc}")

    ; Step 2: Send Alt+E to trigger AI Assistant (before refinement)
    Send("!e")

    ; Step 3: Wait longer for the refinement process to complete
    Sleep(5000) ; Adjust based on actual refinement time (increase delay if needed)

    ; Step 4: Manually reselect the refined suggestion
    Send("!e") ; Assuming Alt+E is still used to select refined suggestions

    ; Step 5: Wait briefly to ensure selection is processed
    Sleep(200)

    ; Step 6: Send Ctrl+Enter to confirm translation
    Send("^Enter")
    }
    }

    emoji
Children