Set an Intel MacBook battery charge limit from Linux.
The tool writes the Apple SMC BCLM and BFCL keys. It is intended for Intel
MacBooks where those keys exist, but Linux does not expose a standard
charge_control_end_threshold battery setting.
Tested on:
- Apple MacBookAir6,2
- Linux 7.0.0-1-cachyos
The program refuses to run unless DMI reports Apple Inc. and a product name
starting with MacBook. It does not expose arbitrary SMC writes.
Clone the repository:
git clone https://github.com/jtbrough/macbook-charge-limit.git
cd macbook-charge-limitBuild:
makeRead the current SMC values:
sudo ./macbook-charge-limit readSet a limit:
sudo ./macbook-charge-limit set 80Reset to full charge:
sudo ./macbook-charge-limit resetValid limits are 20..100.
sudo make install
sudo systemctl daemon-reload
sudo systemctl enable --now macbook-charge-limit.serviceInstalled files:
/usr/local/bin/macbook-charge-limit
/etc/macbook-charge-limit.conf
/etc/systemd/system/macbook-charge-limit.service
make install does not overwrite an existing config file.
Edit:
/etc/macbook-charge-limit.conf
Example:
LIMIT=80Apply a config change:
sudo systemctl restart macbook-charge-limit.serviceCheck the configured value:
sudo macbook-charge-limit readExpected output for an 80% limit:
BCLM=80 BFCL=80
The limit does not discharge a full battery down to the target. To verify it, drain below the configured limit, plug in AC, and watch the battery stop near the limit:
watch -n 10 'printf "AC="; cat /sys/class/power_supply/ADP1/online; for f in status capacity charge_now charge_full current_now voltage_now; do printf "%s=" "$f"; cat "/sys/class/power_supply/BAT0/$f"; done'When the limit is honored, AC is connected, current_now is 0, and status
is usually Full or Not charging.
git pull
make
sudo make install
sudo systemctl daemon-reload
sudo systemctl restart macbook-charge-limit.serviceReset the SMC limit before removing the binary if you want normal 100% charging:
sudo macbook-charge-limit resetDisable the service and remove installed files:
sudo systemctl disable --now macbook-charge-limit.service
sudo make uninstall
sudo systemctl daemon-reloadRemove the config if it is no longer needed:
sudo rm -f /etc/macbook-charge-limit.confThis is a userspace workaround. Native desktop integration depends on a kernel driver exposing the standard power-supply threshold interface.
This tool exists because Linux has no native way to set a MacBook's charge limit. That's being worked on upstream, and this section tracks it. Once the kernel and UPower changes below land in a released distro, this project becomes unnecessary for most users.
Pending review:
- [PATCH v2 0/2] hwmon: (applesmc) add charge_control_end_threshold support
- upower!346: prefer live sysfs threshold values over hwdb CHARGE_LIMIT default
The two kernel patches add real charge_control_end_threshold sysfs support
to applesmc, backed by the actual Apple SMC BCLM key. The UPower change
fixes a separate bug where UPower (and anything reading its D-Bus property,
like KDE's battery applet) shows a static default instead of the real
configured threshold.