Created
March 22, 2019 00:24
-
-
Save tobsn/cb182cbe03d4cbeabb572c1391ef1ec4 to your computer and use it in GitHub Desktop.
osx battery low apple script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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