Enabling "show battery percentage" via script or policy?

DanJ_LRSFC
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.

Thanks,
Dan Jackson (Lead ITServices Technician).

5 REPLIES 5

psliequ
Contributor III
Contributor III

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

#!/bin/sh

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

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

sudo -u $currentUser killall SystemUIServer

a_holley
Contributor

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?

mschwarze
New Contributor II

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

JarvisUno
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.

#!/bin/sh
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.

emarks
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)