Created
January 27, 2020 21:40
-
-
Save Miigon/545e711090d345b7cdbb455c1ca5c23f to your computer and use it in GitHub Desktop.
My pmset configuration on my MacBook Pro 13'' Early 2015
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
#!/bin/bash | |
# macOS power management settings optimized for longer battery life | |
# Tested on MacBook Pro 13'' Early 2015 | |
# Miigon 2020-01-28 | |
echo " " | |
echo "######################## DISCLAIMER ########################" | |
echo "Although this script can be run, it's more intended to show" | |
echo "you how to configure pmset options and explain the options " | |
echo "to you. " | |
echo "You are suggested to read through the script and adjust " | |
echo "them to suit your own need. " | |
echo " " | |
echo "If you really want to use my configuration, which is for a " | |
echo "MacBook Pro, configured to save more power on battery and " | |
echo "get more functionalities on AC power, and goes into hibern-" | |
echo "ation much more frequently than default, please type 'yes'," | |
echo "other inputs will be interpreted as no. " | |
echo " -- Miigon " | |
echo "############################################################" | |
echo "Please type (yes or no): " | |
read INPUT | |
if [ "$INPUT" = "yes" ] | |
then | |
echo "[Script] Applying settings..." | |
echo "[Script] Note that you can always restore your settings back to" | |
echo "[Script] default with \`sudo pmset restoredefaults\`." | |
echo " " | |
else | |
exit | |
fi | |
### TERMS USED IN THIS SCRIPT AND `pmset` UTILITY | |
# | |
# [1]`sleep` | |
# Refers to the kind of sleep in which the system still powers the RAM | |
# and wakes up from the RAM. It's fast and doesn't write to the SSD, | |
# but it consumes more power while sleeping. | |
# | |
# [2]`hibernation`,`standby`,`deep sleep`: | |
# They all refers to the kind of sleep in which the system writes it's whole | |
# memory onto the disk and turns off power for RAM. | |
# This type is the most power-saving but is the slowest to wake up from. | |
# | |
# Because it writes the whole memory to the disk, it also uses SSD write | |
# cycles and may have an impact on it's lifetime. | |
# `standby` == `hibernate`. | |
### ABOUT THE USAGE OF `pmset` | |
# | |
# `-BATTERY-` means the value will be used when using battery and is set by: | |
# pmset -b [option] [value] | |
# | |
# `-AC POWER-` means the value will be used when using AC power adaptor and is set by: | |
# pmset -c [option] [value] | |
# ("c" stands for "charger" here) | |
# | |
# `-BATTERY & AC POWER-` means the value will be used under both circumstances, set it by: | |
# pmset -a [option] [value] | |
# you can split it into two commands, one for battery and one for AC power, and thus create | |
# different settings for different situations. | |
############################### | |
# Safe Sleep | |
############################### | |
### hibernatemode | |
# Also known as `safe sleep`. | |
# hibernatemode = 3 is the default value on portables. The system will store a copy | |
# of memory to persistent storage (the disk), and will power memory during | |
# sleep. The system will wake from memory, unless a power loss forces it to | |
# restore from hibernate image. | |
# SEE MORE: type `man pmset` in terminal and look for `SAFE SLEEP ARGUMENTS` | |
# -BATTERY & AC POWER- | |
sudo pmset -a hibernatemode 3 | |
############################### | |
# Standby (deep sleep) | |
############################### | |
### standby | |
# Hibernates after the system has slept for a specified time period. | |
# -BATTERY & AC POWER- | |
sudo pmset -a standby 1 # Enabled | |
### standbydelayhigh and standbydelaylow | |
# Delay time before the system goes into full hibernate.(in seconds) | |
# These determines how long the system will stay in sleep mode (can wake up fast but consumes more battery) | |
# before writing its memory to disk and powering off its RAM (hibernate). | |
# `standbydelayhigh` is used when the battery is over a certain threshold and `low` is used when it's below that. | |
# The default threshold value is 50%, but can be changed by `pmset -a highstandbythreshold [PERCENT]` | |
# -BATTERY- | |
sudo pmset -b standbydelayhigh 1800 # (30 mins when above 50%) | |
sudo pmset -b standbydelaylow 900 # (15 mins when below 50%) | |
# -AC POWER- | |
sudo pmset -c standbydelayhigh 3600 # (60 mins when above 50%) | |
sudo pmset -c standbydelaylow 1800 # (30 mins when below 50%) | |
# NOTE that having a too short standbydelay will increase the chance of which the whole memory is written | |
# to the disk. This could be a bad thing if you are using a modern mac with a SSD since it increases the | |
# use of write cycles and will shorten the lifetime of your SSD in the long run. | |
# Default values is `86400` and `10800` (24hrs and 3hrs respectively), normally you want it to be slightly | |
# LONGER than how long you typically leave your laptop sleeping before using it again on daytime. | |
# This ensures fast wakeup when you're using it to do your job and makes sure that it goes into hibernation | |
# when left overnight. | |
# note that sleeping isn't going to cost you a lot more power than hibernation, so there's no need to set it | |
# to something extremely low like 5 mins. | |
### autopoweroff | |
# According to `man pmset`, it's an extra implementation of safe sleep to | |
# fulfill regulatory requirement, so it should have the same effect as standby. | |
# just set it to the same value as `standbydelay`. | |
# -BATTERY & AC POWER- | |
sudo pmset -a autopoweroff 1 # Enabled | |
sudo pmset -a autopoweroffdelay 3600 # (60 mins) | |
############################### | |
# Misc. | |
############################### | |
### tcpkeepalive | |
# Mainly used by apsd(ApplePushServiceDaemon) to report the system's state of being online. | |
# Often people find (in their `pmset -g log` output) that apsd and mDNSResponder is constantly waking up | |
# their system. Resulting in battery consumption (in my case about 25% over the course of 24hrs). | |
# Disabling this option prevents that because it keeps the system from connecting to the internet while sleeping. | |
# | |
# ! WARNING: Critical features like `Find My Mac` WILL NOT FUNCTION at sleep when this option is disabled. ! | |
# ! If there's a high chance that your laptop could be lost, set both battery and ac power to 1. ! | |
# -BATTERY- | |
sudo pmset -b tcpkeepalive 0 # Disabled | |
# -AC POWER- | |
sudo pmset -c tcpkeepalive 1 # Enabled | |
### powernap | |
# Wakes up the system while sleeping occasionally to check emails etc. | |
# depends on whether you need it or not, can be changed from System Preferences. | |
# Below is my configuration: | |
# -BATTERY- | |
sudo pmset -b powernap 0 # Disabled | |
# -AC POWER- | |
sudo pmset -c powernap 1 # Enabled | |
### wake on magic packet | |
# Sometimes referred as `Wake on LAN`, this feature enables the device to be waken when a | |
# special packet sent by usually another device on LAN is received. | |
# Not frequently used in real life scenarios, disabling it wouldn't cause any problem. | |
# But for the same reason, don't expect too much beneficial effects by disabling it. | |
# -BATTERY & AC POWER- | |
sudo pmset -a womp 0 # Disabled | |
echo "[Script] Done, use \`pmset -g\` to check your new settings." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment