Here are a few - pointers.
The command you’re looking for is wmctrl.
You may have to go through a lot of trial and error to get what you want. If you succeed, it would be nice to see the fruits of your success here.