I have an Apple Wireless Keyboard and a Magic Trackpad, and I was wondering if there is a way to monitor the battery life remaining/percentage like there is in OSX.
5 Answers
There isn't a GUI for read wireless mouse or keyboard battery data.
You can find useful information on sysfs under /sys/class/power_supply/. For example the Apple Wireless Keyboard is under /sys/class/power_supply/hid-78:CA:39:4E:6F:C7-battery/. In the device directory there is a file named capacity, this is a capacity in percents.
So in summary, for reading Apple Wireless Keyboard battery capacity you should do:
cat /sys/class/power_supply/hid-78:CA:39:4E:6F:C7-battery/capacity
Note that hid-78:CA:39:4E:6F:C7-battery can be different for your device.
According to this article on webupd8, this functionality is planned for Ubuntu 11.10 as part of Ubuntu's new Power Indicator.
- 14,911
if you are using your magic keyboard on Linux (I'm using Ubuntu 20.04), In settings, Select Power Statistics and look for keyboard
- 11
Based on Daniele Napolitano answer I created this simple python script to print the battery percentage of my magic trackpad and my magic keyboard.
Maybe this can be useful to someone.
#!/usr/bin/env python3
import sys
import subprocess
def run_command_or_die(command: str) -> str:
try:
result = subprocess.check_output(
command, shell=True, text=True).strip()
return result
except subprocess.CalledProcessError as e:
print(f"Error executing command: {e}")
sys.exit(1)
names = run_command_or_die('cat /sys/class/power_supply/hid-/model_name')
capacities = run_command_or_die('cat /sys/class/power_supply/hid-/capacity')
sp_names = names.split('\n')
sp_capacities = capacities.split('\n')
if len(sp_capacities) != len(sp_names):
sys.exit('Names and capacities do not match')
print(f"{sp_names[0]}: {sp_capacities[0]}%")
print(f"{sp_names[1]}: {sp_capacities[1]}%")
Example:
$ python3 ,battery_magic_hid.py
Magic Trackpad de Yohann: 48%
Magic Keyboard de Yohann: 70%
- 1
- 1

