Seem like udev should be able to detect if power cord is in
Should be worth looking at
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/bin/powersave true" SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/bin/powersave false"
Read more: Link - Howto: Powersaving tweaks with a udev rule - HOW TO & FAQ Guides - Neowin Forums