There is no scripting process inside calibre GUI other than plugins and python programs run in calibre's context (calibre-debug -e).
You can do some, perhaps all, of what you want to do using the command line, which can be scripted using .bat files (assuming you are using windows). The multi-library stuff won't be straight-forward, requiring an export, and import, and then a delete. It also won't be trivial to do the searching to get the book IDs to operate upon.
As for GUI keypress macro programs, I have no idea. Google finds
http://www.autohotkey.com/ as well as others.