Battery levels widget screenshot

Script

Battery levels

by Wayne Folta

The Apple Batteries widget can only show 4 things (in Small and Medium size) and you exceed that if you use an Apple Magic Keyboard (1), Apple Magic Trackpad (1), Apple Airpods (2) and your MacBook Pro itself (1). So I made this widget that is plain text, but does the job. I run it from cron every 15 minutes.

Script (widget-batteries.sh)

/usr/bin/pmset -g accps \
| LC_ALL=C tr '\325\t' "' " \
| /usr/bin/sed -E 's/;.*//; s/[[:space:]]*\([^)]*\)//; s/^[[:space:]-]+//' \
| /usr/bin/awk '
    /^Now drawing/ { gsub(/'\''/, ""); print; next }
    {
      pct = $NF
      $NF = ""
      sub(/[ \t]+$/, "")
      printf "%-28s %4s\n", $0, pct
    }
  ' | /Applications/TerminalWidget.app/Contents/MacOS/TerminalWidget --target widget2 --font "Roboto Mono" --text -

Download script

← All recipes