Create a button to open/close application

Hello, new to MetaGrid Pro. How do you create a button to open and close an application. I was able to create a button that is linked to a Macro - Launch Application. This works to launch an app if it isnt already active. How would make it to also open the application window if it has been minimized in the dock, and also be able to close the appliction by pressing the same button?