See BU-808: How to Prolong Lithium-based Batteries.
Several of the following are also compatible with Intel machines, although their functionality may be limited to when the laptop lid is open. For detailed information, please consult their respective documentation.
- zackelia/bclm: macOS command-line utility to limit max battery charge
- actuallymentor/battery: CLI for managing the battery charging status for M1 Macs
- GitHub - rurza/BatFi: Battery charging limiter for macOS.
- GitHub - DevNulPavel/osx~batterychargelimit~: Intel-only Macbook (OSX) limit maximum battery charge using SMC
- AlDente (Proprietary, Not Recommended)
To install smc
on your macOS, follow these steps:
# Install smcfancontrol using Homebrew
brew install --cask smcfancontrol
# Copy the 'smc' binary to /usr/local/bin/ for global access
sudo cp '/Applications/smcFanControl.app/Contents/Resources/smc' /usr/local/bin/
To avoid entering your password every time you use the smc
command with sudo
, you can update the sudoers file.
- Open the sudoers file using the
visudo
command:
sudo visudo
Or if you don't know vi
/vim
:
sudo VISUAL=nano visudo
- Scroll to the bottom of the file and add the following line. Replace
username
with your actual macOS username:
username ALL=(ALL) NOPASSWD: /usr/local/bin/smc
- Save and exit the editor.
Make sure you have added the provided Zsh functions in battery_limit.zsh
to ~/.zshenv
or another Zsh configuration file.
-
To enable the battery charge limit:
battery-charge-limit-enable
-
To disable the battery charge limit:
battery-charge-limit-disable
-
To check the status of the battery charge limit:
battery-charge-limit-status
With these functions in place and smc
installed, you can easily manage the battery charge limit of your macOS device from the terminal.
To ensure that the battery charge limit is applied automatically after each system restart, you can use cron
, a time-based job scheduler, to execute the necessary command upon startup. Here's how to set it up:
-
Ensure that the Zsh helper functions (
battery-charge-limit-enable
,battery-charge-limit-disable
, andbattery-charge-limit-status
) are defined in~/.zshenv
since this file is sourced by all instances of Zsh, including non-interactive shells that run during the startup process. If you had previously placed the functions in~/.zshrc
, please move them to~/.zshenv
. -
Open the terminal and type the following command to find out where
zsh
is installed:
which zsh
The command will output the path to zsh
, which usually is /bin/zsh
. Note this path as you will need it for the crontab
entry.
- Open the terminal and access the
crontab
configuration file by typing the following command:
crontab -e
- If you're not familiar with
vi
orvim
, the default editors in the terminal, you might want to switch to a more user-friendly editor temporarily. To usenano
as the editor forcrontab
, for instance, use this instead:
VISUAL=nano crontab -e
- In the
crontab
editor, set theSHELL
variable to ensure thatzsh
is used. Then, add a new line to specify the job that should run at reboot:
SHELL="/bin/zsh" # Replace "/bin/zsh" with the actual path if different
@reboot battery-charge-limit-enable
- Save and exit the editor. If you're using
nano
, you can do so by pressingCTRL+X
, thenY
to confirm the changes, andEnter
to write to the file.
This needs an updated firmware on an Apple Silicon machine.
Thank you, that worked!