Solution for macOS Sierra battery time indicator

9 April 2017

Due to force majeure, the macOS developing team decided to remove the “Time Remaining” voice from the battery life indicator.

Many macOS-based developers and Apple bloggers came up almost immediately with several solutions ranging from replacing the Battery.menu file to more user-friendly solutions such as iStat Menus or coconutBattery, which I strongly recommend.

An engineeristic approach

Since I’m a software engineer, I decided to write my own script and integrate it into an Alfred workflow to see the battery time whenever I have the need. The script that regulates this workflow relies on pmset -g batt, the command line utility that manages and manipulates the Mac power management.

mode=$(pmset -g batt | tail -n1 | awk '{print $4}')+
out=$(pmset -g batt | tail -n1 | awk '{print $5}')
case $mode in
"discharging"*)
	if [[ $out == "(no" ]]
	then echo "Calculating Time Remaining..."
	else echo "$out Remaining"
	fi;;
"charging"*)
	if [[ $out == "(no" ]]
	then echo "Calculating Time Until Full…"
	else echo "$out Until Full"
	fi;;
"charged"*)
	echo "Battery Is Charged";;
"AC"*)
	echo "Battery Is Not Charging";;
"+")
	low=$(pmset -g batt | awk '{print $5}' | tail -n2)
	if [[ $low == "(no"* ]]
	then echo "Calculating Time Remaining..."
	else echo "→ WARNING ←" && echo "$low Remaining"
	fi;;
esac

Taking advance of the Large Type feature available in Alfred, I came up with an intrusive but fast way to check the remaining battery time (or the remaining time to be fully loaded, if attached to the power). I set up two ways to call the workflow: by typing battery1 in the Alfred spotlight, or simply by pressing ⌘+⇧+B2.

Workflow animation

At the following link you can download the workflow for Alfred.

  1. Once Alfred spotlight has learned and cached your search behaviours, you won’t have to type the full keyword anymore. In my case bat is already enough to get it on top of my search results, but is still less efficient than invoking it through the keystroke. 

  2. Both commands can be easily customised after importing the workflow.