Sometimes I want to set a very specific position for an alert, dialog window, etc.
Using the window tokens and trying to guess their values is always a big confusing to me and something that seems very slow.
I was trying to find a way to have an AppleScript that gets the X and Y values of the frontmost window (which I will drag to the desired position), relative to the top left corner of the screen and then save those values to the clipboard, but no matter what I do, I can't make it work.
For example this script gets the coordinates of Keyboard Maestro's Editor window, but not a dialog box that I "triggered" from a different macro, even when I click it to make it the focus (and frontmost) window:
tell application "System Events"
set frontApp to first application process whose frontmost is true
tell front window of frontApp
set windowPosition to position
end tell
end tell
It seems that the script is ignoring the dialog as the frontmost window.
I then went to Activity Monitor and saw that I have 3 "osascript" processes running and when I close the dialog window I triggered, I get 2, so that tells me that the process I need to target is osascript so I used:
tell application "System Events"
tell front window of "osascript"
set windowPosition to position
end tell
end tell
but since I have 3, how would it know which to target?
So I get this error, not sure if it's related?
2024-06-08 09:46:32 Action 15910677 failed: Execute an AppleScript failed with script error: text-script:91:99: execution error: The variable position is not defined. (-2753)
So how could I target the frontmost window of the osascript window?
I even tried an IF THEN action with a condition to check the title of the dialog window, but that doesn't work either. It always shows me a "false" result.

When I hover over the dialog window using UI Browser I get that the application is osascript and it's window 1. Those are the only 2 things in UI Browser



