Detect battery percentage applescript
Here is an example of setting the percent charged of the internal battery to a variable using AppleScript.

In the sample code below the batteryPercent variable holds the numeric percentage of battery charge and is shown in a message.

set batteryPercent to do shell script "pmset -g batt | awk '/InternalBattery/ { sub(/;/, \"\"); print $2 }'"

display dialog "Battery is " &amp; batteryPercent &amp; " charged." buttons {"OK"} default button "OK"