Define -Translate -Synonyms of Highlighted using Copilot

Hello all

I want to use AHK to do :
1- explain/define the highlighted terms

2- Translate to Arabic

3- Give Synonyms - Examples of use.

what is wrong in this code

; Example AHK script to achieve the desired functionality
; When Ctrl+F6 is pressed while text is highlighted, a menu pops up with prompts to choose from

^F6::
    ; Get the highlighted text
    Clipboard := ""
    Send ^c
    ClipWait, 1

    ; If text is not empty, show the menu
    if (Clipboard != "")
    {
        Menu, MyMenu, Add, Define/Explain the highlighted term, DefineExplain
        Menu, MyMenu, Add, Translate the highlighted into (Language - Arabic), TranslateArabic
        Menu, MyMenu, Add, Suggest synonyms of the highlighted, Synonyms
        Menu, MyMenu, Show
    }
return

DefineExplain:
    ; Send the prompt to Copilot
	Run, https://copilot.microsoft.com/
    SendInput define/explain the highlighted term
return

TranslateArabic:
    ; Send the prompt to Copilot
	Run, https://copilot.microsoft.com/
    SendInput Translate the highlighted into (Language - Arabic)
return

Synonyms:
    ; Send the prompt to Copilot
	Run, https://copilot.microsoft.com/
    SendInput suggest synonyms of the highlighted with examples of use
return

emoji
Parents
  •  

    what is wrong in this code

    I run your script and I get what I expected.

    I guess you know that:

    • You’d need a Sleep command before the SendInput lines in order to let your browser to open the Copilot web page.Try with Sleep 2000 and then decrease the 2 seconds timer if it’s too high.
    • The appropriate text box to input the prompt should have the focus, so the string after SendInput goes to something meaningful.
    • And finally, you’d need to press an Enter button to actually run the prompt. SendInput {Enter} will make it.

    What do you expect that is not happening?

    emoji
  • Thank you for your reply

    I need the term and the prompt to be written to get the answer from Copilot

    -----------------

    ; Example AHK script to achieve the desired functionality
    ; When Ctrl+F6 is pressed while text is highlighted, a menu pops up with prompts to choose from
    
    ^F6::
        ; Get the highlighted text
        Clipboard := ""
        Send ^c
        ClipWait, 1
    
        ; If text is not empty, show the menu
        if (Clipboard != "")
        {
            Menu, MyMenu, Add, Define/Explain the highlighted term, DefineExplain
            Menu, MyMenu, Add, Translate the highlighted into (Language - Arabic), TranslateArabic
            Menu, MyMenu, Add, Suggest synonyms of the highlighted, Synonyms
            Menu, MyMenu, Show
        }
    return
    
    DefineExplain:
        ; Send the prompt to Copilot
    	Run, https://copilot.microsoft.com/
    Sleep 1000
        SendInput define and explain the highlighted term
    SendInput {Enter}
    return
    
    TranslateArabic:
        ; Send the prompt to Copilot
    	Run, https://copilot.microsoft.com/
    Sleep 1000
        SendInput Translate the highlighted into (Language - Arabic)
    SendInput {Enter}
    return
    
    Synonyms:
        ; Send the prompt to Copilot
    	Run, https://copilot.microsoft.com/
    Sleep 1000
        SendInput suggest synonyms of the highlighted with examples of use
    SendInput {Enter}
    return
    

    emoji
  •   

    I couldn’t see the video in this forum, but I downloaded and watched it in local mode.

    First, the 1000 ms timer is too short. The web page is not opened yet when the SedInput commad kicks in. Set the timer parameter of Slepp at least to 4000 and see what happens. 

    Second, the text box doesn’t have the focus. It works for me if I press SHIFT+TAB 4 times.

    Taking this into account, the following script works for me:

    DefineExplain:
        ; Send the prompt to Copilot
        Run, https://copilot.microsoft.com/
        Sleep 4000 ; needed to let the browswer to open the webpage
        SendInput {Shift down} ; Hold the SHIFT key down
        Loop 4
        {
            SendInput {Tab}
            Sleep 200
        }
        SendInput {Shift UP} ; Free the SHIFT key
        SendInput define/explain the highlighted term
        SendInput {Enter} ; to run the prompt
    return

    Screenshot of a web browser with a text box containing the text 'defineexplain the highlighted term' and a visual indicator for pressing the 'Tab' key.

    Not tested heavily though…

    You will need to do the same with TranslateArabic and Synonyms labels.

    emoji


    Generated Image Alt-Text
    [edited by: Trados AI at 2:33 PM (GMT 1) on 9 Apr 2024]
  • I found Copilot preview in the Tray

    could you please modify the code to launch Copilot Preview instead of the Browser

    Screenshot of Trados Studio software showing a text document in the Editor view with highlighted text and a Copilot preview icon in the system tray indicated by a red arrow.

    emoji


    Generated Image Alt-Text
    [edited by: Trados AI at 2:59 PM (GMT 1) on 9 Apr 2024]
  •  

    could you please modify the code to launch Copilot Preview instead of the Broweser

    I’m sorry, I don’t use Copilot and I don’t know how to open it from the Tray.

    emoji
  • I discovered a better way to do something very similar, but it uses OpenAI (via the API), instead of Copilot. It's AHK, so very easy to add custom prompts. You can basically create prompts to do anything you can imagine, and the results are instantaneously pasted at your cursor. I wrote a short article about it @ https://beijer.uk/blog/two-autohotkey-scripts-to-select-amp-process-text-with-the-chatgpt-api .

    Screenshot showing a context menu with options 'Fix spelling' and 'Translate' next to selected text, with a green arrow pointing to the menu.

    I also made a quick screencast: app.screencast.com/R9t6kwyrl5225

    emoji


    Generated Image Alt-Text
    [edited by: RWS Community AI at 4:18 PM (GMT 1) on 19 Jul 2024]
Reply Children