Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Should `hs.battery.otherBatteryInfo()` provide battery info for connected AirPods? #1608
I see that the recently-added
Should Apple AirPods be included in the battery info returned by
Is there a way to fetch the battery info for AirPods via Hammerspoon?
If it's not showing up in the others, then at present, no, I don't believe Hammerspoon currently can detect these. The "otherBatteryInfo" function iterates through the IOKit service plane registry and looks for items which have a "BatteryPercent" field, so if the key name is different or if the air pods are registered in a different plane, the current code would miss them.
If you know of sample code online which does return the battery level for the airpods, I'll be happy to compare them and see what changes we can make to also capture the information, but as I don't have them myself, I can't really test it. If you have XCode installed on your computer, you might do some digging with the "ioRegistryExplorer" application and see if you can identify the field name we should be looking for.
(as an aside, this is not the first time Apple has changed field names, sometimes even between different firmware versions of the same product... it makes targeted IOKit queries problematic, but my first attempts at a generic IOKit module didn't work so well... it may be time to think about trying again because investigating this in the Hammerspoon console would be soooooo much easier!)
@asmagill: Thanks for the reply!
I see the AirPods in the IORegistryExplorer, but I don't see the battery info:
duk242/AirPodsBatteryCLI does the trick. Example usage:
To get those results, AirPodsBatteryCLI shells out to run a
Unfortunately it involves using private Apple APIs, but they are sufficiently rich that I couldn't resist adding it. Please do be aware that this can/will break in any future macOS update, but it works at least for 10.13.1 and currently has no kind of safety net. If people report crashes, the latter can change