Answers:
您可以从命令中找到此信息以及其他许多电池和/或系统信息
ioreg
根据其手册页,此命令执行以下操作:
ioreg显示I / O Kit注册表。它以分层树的形式显示了1类注册表结构。
1:分层[sic]
使用按类名称的过滤器(AppleSmartBattery
用于电池)仅获取与电池有关的信息:
$ ioreg -brc AppleSmartBattery
-b Show the object name in bold. -r Show subtrees rooted by objects that match the specified criteria. If none of -c, -k, or -n are supplied, -r has no effect. -c Show the object properties only if the object is an instance of, or derives from, the specified C++ class (e.g. IOService).
来自
man ioreg
。
将打印如下内容:
$ ioreg -brc AppleSmartBattery
+-o AppleSmartBattery <class AppleSmartBattery, id 0x100000254, registered, ma$
{
"ExternalConnected" = Yes
"TimeRemaining" = 0
"InstantTimeToEmpty" = 65535
"ExternalChargeCapable" = Yes
"FullPathUpdated" = 1464849055
"CellVoltage" = (4298,4292,4299,0)
"Voltage" = 12889
"BatteryInvalidWakeSeconds" = 30
"AdapterInfo" = 0
"MaxCapacity" = 5524
"PermanentFailureStatus" = 0
"Manufacturer" = "SMP"
"Location" = 0
"CurrentCapacity" = 5524
"LegacyBatteryInfo" = {"Amperage"=0,"Flags"=5,"Capacity"=5524,"Current"=5$
"FirmwareSerialNumber" = 1
"BatteryInstalled" = Yes
"PackReserve" = 200
"CycleCount" = 318
"DesignCapacity" = 6330
"OperationStatus" = 58371
"ManufactureDate" = 17726
"AvgTimeToFull" = 65535
"BatterySerialNumber" = "D864403T3UVFVN7A6"
"BootPathUpdated" = 1464353527
"PostDischargeWaitSeconds" = 120
"Temperature" = 3096
"UserVisiblePathUpdated" = 1464849490
"InstantAmperage" = 0
"ManufacturerData" = <000000000702000a03890000034a34340330304103534449032$
"MaxErr" = 1
"FullyCharged" = Yes
"DeviceName" = "bq20z451"
"IOGeneralInterest" = "IOCommand is not serializable"
"Amperage" = 0
"IsCharging" = No
"DesignCycleCount9C" = 1000
"PostChargeWaitSeconds" = 120
"AvgTimeToEmpty" = 65535
}
您正在寻找的领域是DesignCapacity
。为方便起见,将其过滤掉grep
(单位为毫安小时或mAh):
$ ioreg -brc AppleSmartBattery | grep DesignCapacity
"DesignCapacity" = 6330
您的DesignCapacity
字段可能不会显示6330
为其值。我正在使用2014年中期的13英寸rMBP,但您可能正在使用另一台电池额定功率不同的系统。
除了电池信息外,ioreg
还可用于查找有关系统和其他外围设备的更多信息-有点像命令行系统信息工具。
如果您正在寻找此命令的代码实现,请在Github上查看Beltex的SystemKit。这是我所知道的最酷的Swift库之一。
免责声明:不隶属于SystemKit或Beltex。只是SystemKit的快乐用户。