I'm lumping a couple of questions together here because they all relate to the same desired macro – hope that's okay.
The general problem is that when a ChatGPT window is narrow beyond a certain point (somewhere between 50 and 60% on my 13" MacBook Air, I think), for some reason hitting return doesn't send the query as it should, but gives me an undesired return in the text field. I've collaborated for hours with ChatGPT on this, but don't as yet have something that works.
One clunky thing we tried today, triggered by the return key, was getting the size and position of the front browser window, expanding it to full screen to have it always the same size and position when clicking on the Send button, and then restoring the original window size and position. This was impractical (aside from not working), as there would be a delay in any event and particularly when delays were inserted as needed in the AppleScript.
So I'm ready to dump this approach and try something else, but I'm curious about the click and would like to get it to work even though I don't plan on using this version of the macro in any event. Here's the AppleScript with my best stab at the needed click percentages:
-- Use shell script to get screen dimensions
tell application "System Events"
set screenResolution to do shell script "system_profiler SPDisplaysDataType | awk '/Resolution:/{print $2, $4}'"
set spacePos to offset of " " in screenResolution
set screenWidth to text 1 through (spacePos - 1) of screenResolution
set screenHeight to text (spacePos + 1) through end of screenResolution
end tell
-- Define the coordinates for the "Send" button, ensure these are correct
set clickX to screenWidth * 0.82 -- calculated using cmd-shift-4/KM coordinates
set clickY to screenHeight * 0.93 -- calculated using cmd-shift-4/KM coordinates
-- Manipulate Brave Browser window
tell application "System Events"
tell application process "Brave Browser"
set frontWindow to the first window
-- Get the current position and size of the window
set {windowX, windowY} to position of frontWindow
set {windowWidth, windowHeight} to size of frontWindow
-- Maximize the window for consistent button location
set position of frontWindow to {0, 0}
set size of frontWindow to {screenWidth, screenHeight}
-- Wait for the UI to update
delay 1
end tell
-- Activate Brave Browser
tell application "Brave Browser" to activate
-- Simulate the click on the Send button
tell application process "Brave Browser"
delay 2 -- Additional delay to ensure Brave is active and ready
click at {clickX, clickY}
-- Restore the original window size and position
delay 1
set position of frontWindow to {windowX, windowY}
set size of frontWindow to {windowWidth, windowHeight}
end tell
end tell
Both cmd-shift-4 and KM gave me about the same coordinates for the Send button {895, 956} and the lower right-hand corner of the screen {1470, 956}. I'm ready to give up on getting the click since I think my calculation was correct or should have been, but I'm still curious as to why the cmd-shift-4/KM coordinates were so incongruous with the results of the shell script (2560 x 1664). Maybe someone can explain this to me before I go on to the other approach.