Skip to content

Instantly share code, notes, and snippets.

@suranap
Created May 6, 2023 00:26
Show Gist options
  • Save suranap/c455b7259d0f43a6775cd96ef6051249 to your computer and use it in GitHub Desktop.
Save suranap/c455b7259d0f43a6775cd96ef6051249 to your computer and use it in GitHub Desktop.
Low power mode for Macs
<?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>
-- 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
@suranap
Copy link
Author

suranap commented May 6, 2023

To install:

  1. Paste AppleScript code into Script Editor. Save somewhere.
  2. Copy plist file to /Library/LaunchDaemons under some name
  3. Change label on line 6
  4. sudo launchctl start <your plist file>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment