Copy last message of a AI Chat

We have an older answer on automating chatgpt, but in 2025 it seems that using the xpath is tricky, ChatGPT tries to prevent this, plus, if the chatgpt answer has more than one paragraph and/or code responses, you would need to parse each paragraph with storeText.

So… the best solution seems to me to automate the click on the ChatGPT “Copy” icon:

Now… the tricky part is that this icon shows only on mouse over, and it position can shift a bit, depending on the length of the answer.

The solution for this is to:

  1. Find the ChatGPT input box with xclick.
  2. From there, xmove the mouse up by e. g. 25 points step by step - until the Copy button appears :eyes:
  3. Then click it - and get the result from the clipboard with ${!clipboard}

Video:

Macro code:

{
  "Name": "GetTextFromChatGPT",
  "CreationDate": "2025-5-26",
  "Commands": [
    {
      "Command": "store",
      "Target": "fast",
      "Value": "replayspeed",
      "Description": ""
    },
    {
      "Command": "XClick",
      "Target": "chatbox_dpi_168.png",
      "Value": "",
      "Description": "Find the chat input box. We know the Copy icon is somewhere above it."
    },
    {
      "Command": "store",
      "Target": "${!IMAGEX}",
      "Value": "x",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "${!IMAGEY}",
      "Value": "y",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "x,y=${x},${y}",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "true",
      "Value": "!errorignore",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "0",
      "Value": "!timeout_wait",
      "Description": "0 -> only one try, then move on"
    },
    {
      "Command": "do",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return Number (${y}) - 25;",
      "Value": "y",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "x,y=${x},${y}",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "XMove",
      "Target": "${x},${y}",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "true",
      "Value": "!statusOK",
      "Description": "Reset the value before image search. This is important, because FALSE does not change back to TRUE by itself!"
    },
    {
      "Command": "XClick",
      "Target": "copy_dpi_168.png",
      "Value": "",
      "Description": "Check for Copy icon (and click it if found!)"
    },
    {
      "Command": "echo",
      "Target": "Copy Image found? ${!statusOK} ",
      "Value": "brown",
      "Description": ""
    },
    {
      "Command": "repeatIf",
      "Target": "${!statusOK} == false",
      "Value": "",
      "Description": "Loop until Copy image is found"
    },
    {
      "Command": "store",
      "Target": "false",
      "Value": "!errorignore",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Last answer copied, the text is: ${!clipboard}",
      "Value": "green",
      "Description": "Get the content from the clipboard with the special variable"
    }
  ]
}

PS: Because the copy icon image shows only on mouse over, it can not be captured with the SELECT button. Insted, we used an external screenshot tool for it and then imported the image:

As image we used

image

This image includes two icons, to make the image search more reliable/robust. The click is always in the center of the image.

2 Likes