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, raging from replacing the Battery.menu file to more user-friendly solutions such as iStat Menus or coconutBattery (which I strongly recommend).

Since I’m not a compulsive battery-life checker, I decided to write a small-but-useful Alfred workflow to see the battery time whenever I have the need. The script that regulates this workflow is nothing but a mixture of pmset -g batt and echo.

workflow-sample

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 time in the Alfred spotlight, or simply by pressing ⌘+⇧+B (but you can easily change both of them).

Without further ado, here you can download my workflow.

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

Feel free to share it and if you improve the workflow, please let me know the features you added so I can take advance of them too.