brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: pmset -g batt prints your MacBook battery state in Terminal

Terminal
~/tips/tip-macos-pmset-g-batt

pmset -g batt

Prints the status of the batteries and power sources of a MacBook from Terminal.

I do not always want to open System Settings just to see the battery. Terminal has a getter for it, and reading does not need sudo.

The man page says -g batt, or the equivalent -g ps, displays the status of batteries and UPSs:

pmset -g batt

It shows the state of all attached power sources, which makes it easy to use in a script. The man page also lists a few other getters:

  • pmset -g pslog displays an ongoing log of power source state, until you press Control-C
  • pmset -g rawlog displays an ongoing log of the battery state as read directly from the battery
  • pmset -g assertions summarizes the power assertions that may prevent system sleep or display sleep
  • pmset -g therm shows thermal conditions that affect CPU speed, and -g thermlog logs such notifications

The man page says pslog and rawlog are normally used for debugging, for example to isolate a problem with an aging battery. The assertions list is the one I would open when a Mac will not sleep, since assertions are what can prevent system sleep or display sleep.

The caveats come from the same page. The thermal getters are not available on all platforms, and the assertions getters are listed as available from 10.6 and later. Also, pmset must be run as root only to modify settings. The getters are safe, but the same command with a setting name, such as displaysleep 5, changes how your Mac behaves, so read the line you paste before you press Return.

Further reading: pmset man page

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link