Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
osx battery low apple script
set Cap to (do shell script "ioreg -w0 -l | grep ExternalChargeCapable")
tell Cap to set {wallPower} to {last word of paragraph 1}
set CurrentVolume to output volume of (get volume settings)
if wallPower = "Yes" then
return 0
else
set Cap to (do shell script "ioreg -wO -l | grep Capacity")
tell Cap to set {Available, Max} to {last word of paragraph 2, last word of paragraph 1}
set Pct to round (100 * (Max / Available))
-- tell application "System Events" to display dialog "Battery is at " & Available & " - " & Max & " - " & Pct & "%"
if Pct < 3 then
set volume output volume 80
do shell script "afplay /System/Library/Sounds/Purr.aiff"
set volume output volume CurrentVolume
-- tell application "System Events" to display dialog "Battery below 3%!"
else if Pct < 5 then
set volume output volume 40
do shell script "afplay /System/Library/Sounds/Purr.aiff"
set volume output volume CurrentVolume
-- tell application "System Events" to display dialog "Battery below 5%!"
end if
end if
#
-- tell application "System Events" to display dialog (get output volume of (get volume settings))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.