What's a way to run an automator/bash/applescript command right when a laptop starts charging and right when it stops being charged?
You can do that very easily using ControlPlane, a free (open-source) application:


  ControlPlane, a fork of MarcoPolo, brings context and location sensitive awareness to OS X. With ControlPlane you can intelligently reconfigure your Mac or perform any number of actions based on input from a wide variety of evidence sources [...]


from: https://github.com/dustinrue/ControlPlane

You can very easily add a "power source rule" which then launches or quits an application or script. As you can see in the attached screenshots, it's very easy to set-up.