I nearly want to support your request, but I think it is just the thin edge of a bigger request. What Photoshop needs is a proper grown up well designed scripting language. But it isn't easy to do that. Microsoft with Excel started with a crummy language for macros, improved it a little then switched to a language they call Visual Basic which is neither Visual not Basic and I think most people who try to use it grizzle and growl and complain and persevere only because alternatives are elusive.
We need the elves at Adobe to do what you ask, but better than Microsoft did it.