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

Disclaimer:


The sample scripts provided below are adapted from third-party open-source sites.

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:

Once brew is installed, run these commands to 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:

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.

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:

Execute this command to undo the persist action:

How to view the existing charging limit?

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:

Output of script to view set battery charge limit

Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository