Category filter
Script to set charging limit on macOS devices
Charging limits are set on macOS devices to prolong their battery health; this is especially beneficial for Macs that are always plugged in as it prevents the battery from constantly being fully charged. When devices are charged to maximum capacity for an extended period, the battery loses its capacity, gradually decreasing its life. When a charging limit is set, the battery will not charge beyond that value, even if it continues to be connected to a power source. Admins may need to employ this battery charging limit in many devices, which could be a hefty task if done manually. This process can be made much more efficient by remotely executing the scripts given below using Hexnode UEM’s Execute Custom Script action.
Scripting Language – Bash
File extension – .sh
How to set charging limit on Macs?
First, install Homebrew if it isn’t already available on the device. Homebrew is a software package management system that simplifies software installation in macOS. Execute the following command to install Homebrew:
1 |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" |
Once brew is installed, run these commands to install bclm:
1 2 |
brew tap zackelia/formulae; brew install bclm |
bclm represents Battery Charge Limit Max, a wrapper to read and write values to the System Management Controller (SMC). SMC controls how the Mac manages its power.
When executing these commands, if a “command not found” error arises, provide the entire path to brew, which can be obtained by running:
1 |
which brew |
For further assistance, check out our document on how to fix common issues while executing custom scripts on Mac.
After the installation of bclm, run the write
command to set charging limit.
1 |
sudo bclm write 77 |
Executing this command will set the charging limit to 77%.
How to make sure the charging limit persists?
The charging limit is set by changing the SMC’s value. To ensure that the value persists and doesn’t reset, execute the following command:
1 |
sudo bclm persist |
Execute this command to undo the persist action:
1 |
sudo bclm unpersist |
How to view the existing charging limit?
1 |
bclm read |
Execute this command to view the battery’s current charging limit in percentage.
The output can be verified under the Action History tab of the device. Since we set the charging limit to 77% using the write
command earlier, the output here will be: