Apple did this back in the mid 1990's (before OSX) with AppleScript. Every application was supposed to ship with metadata that described its object model along with methods that could be invoked on them. AppleScript was an sort of a protocol or interface standard that allowed scripts to automate application actions (and more) without having to use GUI macros. Scripts could be written with a variety of syntaxes. It was pretty cool. However, it turned out that providing an object model and API surface was a pretty heavy lift for application developers and most just half-assed it. And while a fairly robust community developed around AppleScript, it was too small to generate any noticeable uplift in sales for either Apple or independent software vendors. Thus not really commercially viable.
And Microsoft has had OLE -- which is sort of analogous to the object-model portion of AppleScript -- for ages.
My ideas about how to fix this (with a new operating system design) involves:
1. Use of FOSS will be helpful, since it can be improved if something is wrong with it.
2. UI controls are objects with data models like any others are, so even if a API is not provided by a program, these UI controls, and the data associated with them, can be added into scripts like any other API can be.
3. Capabilities are needed for I/O and proxy capabilities can be created and used. Even if the program does not expect the I/O to be filtered or modified, the system forces that it can be done anyways (and the command shell in the system is designed to allow this, too).
4. This metadata is required even for a program to start (due to the way the I/O is working).