Skip to content

Instantly share code, notes, and snippets.

@petr001
Last active May 25, 2020 06:31
Show Gist options
  • Save petr001/678efd4c7398f8d34f57393fdcb94bc5 to your computer and use it in GitHub Desktop.
Save petr001/678efd4c7398f8d34f57393fdcb94bc5 to your computer and use it in GitHub Desktop.
Bitbar (https://getbitbar.com) plugin. Copy to plugin folder and add X permission (`chmod u+x apple-mouse-keyboard-battery.1m.sh`)
#!/bin/sh
# <bitbar.title>Apple Mouse and Keyboard Battery Percentage</bitbar.title>
# <bitbar.version>1.0</bitbar.version>
INFO=$(
ioreg -r -l -n AppleHSBluetoothDevice |
egrep '"BatteryPercent" = |^ \| "Bluetooth Product Name" = ' |
sed 's/ | "Bluetooth Product Name" = "Magic Mouse 2"/🖱 /' |
sed 's/ | "Bluetooth Product Name" = "Magic Keyboard"/\⌨️ /'|
sed 's/ | "BatteryPercent" = //' |
sed -E 's/([0-9]+)/\1% /'
);
if [ "$INFO" ]; then
echo $INFO " | size=12"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment