Open & close apps when charging and not

Is it possible to launch apps when the Mac starts to charge, and close apps when the charger is disconnected?