I took a few seconds to wrap this into a tiny addon (because of the 255 character limit on macros) so some more advanced conditionals (like if target exists, if in combat) could be tested and the macro syntax could be simplified.
http://oldschoolwow.com/AutoPowershift.zip
This addon provides two functions:
-- toggleps(): enable/disable powershifting
-- ps(en): cancel form if powershift is enabled and energy is under the threshold
Toggle:
/run toggleps()
Mangle:
/run ps(18)
/cast [noform] Cat Form; Mangle (Cat)()