Hi All,
I’m writing some relevance to get the battery health from our laptops. For Windows, I’m grabbing from wmi and for Macs, from the iokit registry, like so:
if (exists (setting "_BESClient_ComputerType" of client) whose (value of it is "Laptop")) then (if (windows of operating system) then ((integer value of selects ("FullChargedCapacity from BatteryFullChargedCapacity") of wmi "root/wmi")/(integer value of selects ("DesignedCapacity from BatteryStaticData") of wmi "root/wmi") as floating point * ("100.0" as floating point)) else (if (mac of operating system) then (if (concatenation of unique values of brand strings of processors as lowercase contains "apple") then ((integer of values of entries whose (key of it = "AppleRawMaxCapacity") of dictionary of node "AppleSmartBattery" of node "AppleSmartBatteryManager" of node "AppleSMC" of node "SMCEndpoint1" of node "RTBuddyV2" of node "iop-smc-nub" of node "AppleASCWrapV4" of node "smc" of node "AppleT810xIO" of node "arm-io" of node "AppleARMPE" of service plane of iokit registry)/(integer of values of entries whose (key of it = "DesignCapacity") of dictionary of node "AppleSmartBattery" of node "AppleSmartBatteryManager" of node "AppleSMC" of node "SMCEndpoint1" of node "RTBuddyV2" of node "iop-smc-nub" of node "AppleASCWrapV4" of node "smc" of node "AppleT810xIO" of node "arm-io" of node "AppleARMPE" of service plane of iokit registry) as floating point * ("100.0" as floating point)) else (((integer of value of entry whose(key of it = "MaxCapacity") of dictionary of node "AppleSmartBattery" of node "AppleSmartBatteryManager" of node "AppleECSMBusController" of node "SMB0" of node "AppleACPIPlatformExpert" of service plane of iokit registry)/(integer of value of entry whose(key of it = "DesignCapacity") of dictionary of node "AppleSmartBattery" of node "AppleSmartBatteryManager" of node "AppleECSMBusController" of node "SMB0" of node "AppleACPIPlatformExpert" of service plane of iokit registry) as floating point * ("100.0" as floating point)))) else error "Not supported")) else error "Not a laptop!"
For Intel Macs, the relevant bit from above is:
((integer of value of entry whose(key of it = "MaxCapacity") of dictionary of node "AppleSmartBattery" of node "AppleSmartBatteryManager" of node "AppleECSMBusController" of node "SMB0" of node "AppleACPIPlatformExpert" of service plane of iokit registry)/(integer of value of entry whose(key of it = "DesignCapacity") of dictionary of node "AppleSmartBattery" of node "AppleSmartBatteryManager" of node "AppleECSMBusController" of node "SMB0" of node "AppleACPIPlatformExpert" of service plane of iokit registry) as floating point * ("100.0" as floating point))
And then for (what I thought would be) Apple Silicon I was using:
((integer of values of entries whose (key of it = "AppleRawMaxCapacity") of dictionary of node "AppleSmartBattery" of node "AppleSmartBatteryManager" of node "AppleSMC" of node "SMCEndpoint1" of node "RTBuddyV2" of node "iop-smc-nub" of node "AppleASCWrapV4" of node "smc" of node "AppleT810xIO" of node "arm-io" of node "AppleARMPE" of service plane of iokit registry)/(integer of values of entries whose (key of it = "DesignCapacity") of dictionary of node "AppleSmartBattery" of node "AppleSmartBatteryManager" of node "AppleSMC" of node "SMCEndpoint1" of node "RTBuddyV2" of node "iop-smc-nub" of node "AppleASCWrapV4" of node "smc" of node "AppleT810xIO" of node "arm-io" of node "AppleARMPE" of service plane of iokit registry) as floating point * ("100.0" as floating point))
Unfortunately, it seems the relevance I wrote is only good for M1 chips:
Our M2s, M1 Pros, and other non-M1 Apple chips all report back “Singular expression refers to nonexistent object”. I don’t have any of these devices in front of me to test, but I’m assuming the place where this data is stored has once again changed.
Instead of adding another If…Then…Else clause for each different M-series processor, I’m hoping to adjust the relevance to do that for me. Something like being able to find the node “AppleRawMaxCapacity” without needing to provide the entire path. Is this possible?
Thanks!