Enabling "show battery percentage" via script or policy?

Contributor II

Is there a way to enable "show battery percentage" for MacBooks using a policy and/or a script?

I googled and found ways to display the battery percentage actually within Terminal, but I couldn't see a way to enable it to always be displayed on the menu bar?

The Energy Saver profile settings don't contain a setting for this.

Dan Jackson (Lead ITServices Technician).


Contributor III
Contributor III

Something like this, set either as a login policy or at the next check-in;


currentUser=`ls -l /dev/console | cut -d " " -f4`

sudo -u $currentUser defaults write com.apple.menuextra.battery ShowPercent YES

sudo -u $currentUser killall SystemUIServer


Trying to deploy this via a config profile and it doesn't appear to work.
I assume it has something to do with it being a per user setting as oppose to a global setting?
Am I just better off to deploy this via a script on login for each user?

New Contributor II

We are using the same Script as @psliequ posted. Works fine!

Contributor II

This no longer appears to be working I am trying to incorporate VPN Icon in here as well but my syntax must be be wrong somewhere.

user=$(stat -f %Su /dev/console); 
sudo -u $user open "/System/Library/CoreServices/Menu Extras/vpn.menu"
sudo -u $user defaults write com.apple.menuextra.battery -ShowPercent YES
sudo -u $user killall SystemUIServer

Some assistance would be most appreciated, as I am learning here.

New Contributor

If anyone has an update on this that would be great! It does not seem to be working anymore. (macOS Big Sur 11.4, M1 MacBook Air)