Skip to content

Instantly share code, notes, and snippets.

@javiyt
Created March 11, 2020 09:41
Show Gist options
  • Save javiyt/3ddaf97ce00218ef8fbd40d8a7f315cb to your computer and use it in GitHub Desktop.
Save javiyt/3ddaf97ce00218ef8fbd40d8a7f315cb to your computer and use it in GitHub Desktop.
Automatically charge your Mac Book Pro
do shell script "pmset -g batt | grep InternalBattery | column -t"
set x to the result
set remaining to the word 10 of x
set state to word 7 of x
set percentage to word 6 of x as real
if remaining contains "remaining" then
if state is "discharging" and percentage < 20 then
do shell script "curl -v -XPOST https://maker.ifttt.com/trigger/battery_is_low/with/key/supersecretkey"
else if state is "charging" and percentage > 80 then
do shell script "curl -v -XPOST https://maker.ifttt.com/trigger/battery_has_been_charged/with/key/dsupersecretkey"
end if
end if
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>Label</key>
<string>local.battery</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/osascript</string>
<string>/Users/Me/Documents/Scripts/AppleScript/scripts/battery.applescript</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>60</integer>
<key>StandardErrorPath</key>
<string>/tmp/battery.err</string>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment