Windows at least has AutoHotKey[1] -- it's kind of awful, but also kind of great. It has been a path into programming for more than one person I know and has saved others countless hours of repetition.
An app I built, Keysmith [1], does something pretty close to what you're describing. It's macros anywhere on your Mac, but instead of using OCR we use accessibility APIs to identify UI elements by name. There's also a browser extension to do the same on the web.
And you can save macros for later use or just create a one-off "Scratch" macro as described here [2].
Conceptually yes. I've yet to see one that is built for an end user to make something on a one shot example though, with an output script that you can tweak.
1 - https://www.autohotkey.com/