3

I have tried the following command in macOS to get all the battery information:

  1. pmset -g batt

    The above command is displaying only one information(i.e 35% discharging).

  2. system_profiler SPPowerDataType | grep "Device Name" | awk '{print $3}'

    The above command is displaying device name.

Is there any command by using which together all battery information(Serial Number, Manufacturer, device name, cycle count, charging, etc.),we can fetch. Please help me in finding this. Thanks for your help in advance.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
Lushi Grey
  • 31
  • 1
  • 5
  • Are you asking for a *shell* command, or a C function? – Some programmer dude Nov 30 '18 at 07:14
  • Sorry if I missed to mention this above . Are you asking for a shell command, or a C function? --->shell command. – Lushi Grey Nov 30 '18 at 07:15
  • Then why did you add the `c` tag? No matter which site on the [Stack Exchange network](https://stackexchange.com) you post to, always make sure you select the correct tags. Each tag has a short description, read them before selecting. Also read the help-pages of the site, and learn what kind of questions are on- or off-topic. This, for example, is off-topic here. – Some programmer dude Nov 30 '18 at 07:18
  • I have struggled a lot to finding this.Please help me in this.This is an urgent requirement.:( – Lushi Grey Nov 30 '18 at 07:18
  • And please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](https://meta.stackoverflow.com/questions/326569/under-what-circumstances-may-i-add-urgent-or-other-similar-phrases-to-my-quest) which is really valid for all sites in the Stack Exchange network. – Some programmer dude Nov 30 '18 at 07:19
  • some-programmer-dude--->yes sure dude..I will keep your things in my mind.And thanks for your quick response . – Lushi Grey Nov 30 '18 at 07:20
  • Try `pmset -g accps` and `pmset -g rawbatt` and `pmset -g everything` – Mark Setchell Nov 30 '18 at 13:13

1 Answers1

3

The best command that I could think of is

ioreg -w0 -1 | grep Capacity

For me this returns something like this: | | "AppleRawCurrentCapacity" = 6417

| |           "AppleRawMaxCapacity" = 6834

| |           "MaxCapacity" = 6834

| |           "CurrentCapacity" = 6417

| |           "LegacyBatteryInfo" = {"Amperage"=18446744073709550119,"Flags"=4,"Capacity"=6834,"Current"=6417,"Voltage"=8204,"Cycle Count"=198}

| |           "DesignCapacity" = 7150

| |           "BatteryData" = {"StateOfCharge"=24064,"Voltage"=8204,"QmaxCell1"=46108,"ResScale"=0,"QmaxCell2"=0,"QmaxCell0"=54044,"CycleCount"=198,"DesignCapacity"=7150}

Don't forget that you can combine multiple commands into one to run after the other has completed with && eg:

system_profiler SPPowerDataType | grep "Device Name" | awk '{print $3}' && ioreg -w0 -1 | grep Capacity

You can also replace the word Capacity with things like board-id

If you want to process all this data I would create a bash script to do it for you,

Because you can cut up the lines to display the info that you want like:

ioreg -l | grep board-id | cut -d \" -f 4

Obviously you can just type this into the terminal but doing this for every command gets a bit tyresome!

Combine many of these commands to make a script (or even in python!) that would process all the data and return it in anyway you would like, if that is possible for what you want to use that data for!

I should think that all the possible accessible battery information is found in system information > power:

Battery Information:

Model Information:
Manufacturer:   DP
Device Name:    bq20z451
Pack Lot Code:  0
PCB Lot Code:   0
Firmware Version:   511
Hardware Revision:  000a
Cell Revision:  1210
ETC.....

EDIT:

Istats is a free CLI which allows you to view a lot of info but is obviously not native see https://robservatory.com/see-sensor-stats-in-terminal/

To find the battery temp with a single native command! :

bc <<< "scale=3; `ioreg -r -n AppleSmartBattery | grep Temperature | cut -c23-`/100"

Hope this helps

Archie Webster
  • 334
  • 2
  • 11
  • Thanks a lot artom-web-artomweb!!!! Yes I can combine all seperate commands and make it as single.But the problem is happening like; I want to get the others battery information(Chemistry,Temperature,Estimated time left,current state) as well...which is not present in the System information->Power.. And to get that information,need command.That is the problem..Please help me in resolving this.Thanks again ... – Lushi Grey Nov 30 '18 at 12:59
  • Could you perhaps suggest what you want to do with this command, because there are individual commands to do each thing. I also found a CLI called istats: https://robservatory.com/see-sensor-stats-in-terminal/ – Archie Webster Dec 01 '18 at 01:01
  • Actually I want to fetch battery related all information through one command in Mac platform.Please help me in this.I don't want to merge single single command in one.Thanks in advance. – Lushi Grey Dec 03 '18 at 07:44
  • 1
    I got one command "ioreg -wO -l" to retrieve information about battery..but this command gives unwanted information as well. I want only battery related information and that is present under AppleSmartBattery.So I have used "ioreg -wO -l | grep AppleSmartBattery".But because word "AppleSmartBattery" is present at other place as well,so it is again fetching other information as well. Kindly help me in finding only battery related information.Thanks in advance. – Lushi Grey Dec 03 '18 at 10:27
  • 1
    Can anyone help me in this please? – Lushi Grey Dec 03 '18 at 12:35
  • adding head -1 will fix this after another | – Archie Webster Dec 04 '18 at 08:07
  • Thanks artomweb for your response.Could you please give some example for this so that I will understand clearly. – Lushi Grey Dec 05 '18 at 08:15
  • Why are you using ioreg -wO -l | grep AppleSmartBattery, for me it just returns a load of rubbish compared to my command 'ioreg -r -n AppleSmartBattery'. To find the first result you would type 'ioreg -wO -l | grep AppleSmartBattery | head -1' but because the command doesn't work anyway there is no point. It doesn't work because you are searching everything for AppleSmartBattery instead of just the actual data. – Archie Webster Dec 09 '18 at 10:52
  • To find and print a specific line use | grep '' For example ioreg -r -n AppleSmartBattery | grep '"IsCharging' – Archie Webster Dec 09 '18 at 10:55
  • Thanks Artom Web Artomweb..It's working.Thannks a lot. – Lushi Grey Dec 13 '18 at 11:42
  • One more problem I am facing here,can anybody help me .....Problem is while I am using the above command and getting battery information...but there unit is not displaying...for ex-Temperature value is displaying but how we will come to know that whether it is in Celsius or Kelvin....Please help me out..Thanks in advance... – Lushi Grey Dec 27 '18 at 04:40
  • @LushiGrey It will be in the scale that everything else on your computer is! – Archie Webster Dec 28 '18 at 23:38