Created
May 6, 2023 00:26
-
-
Save suranap/c455b7259d0f43a6775cd96ef6051249 to your computer and use it in GitHub Desktop.
Low power mode for Macs
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>local.droopy.lowpowermode</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/usr/bin/osascript</string> | |
<string>/Users/suranap/.local/scripts/LowPowerMode.scpt</string> | |
</array> | |
<key>StartInterval</key> | |
<integer>1200</integer> | |
</dict> | |
</plist> | |
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
-- Check the battery level | |
set batteryLevel to do shell script "pmset -g batt | grep -Eo \"\\d+%\" | cut -d \"%\" -f 1" | |
set onBattery to do shell script "pmset -g batt | grep -q \"Battery Power\" && echo 1 || echo 0" | |
set onLowPowerMode to do shell script "pmset -g | grep lowpowermode | grep -o \"[0-9]*\" " | |
if onLowPowerMode = "0" and batteryLevel < 20 then | |
do shell script "pmset -a lowpowermode 1" with administrator privileges | |
else if onLowPowerMode = "1" and (batteryLevel > 80 or onBattery = "0") then | |
do shell script "pmset -a lowpowermode 0" with administrator privileges | |
end if |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To install:
sudo launchctl start <your plist file>