Created
August 22, 2022 20:00
-
-
Save lamw/db9ed24b1de56094a8a5036cb73eaba0 to your computer and use it in GitHub Desktop.
Script to check the Apple keyboard/mouse battery percent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
PATH=/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/bin:/usr/sbin:/sbin | |
# actual battery level | |
MOUSE_BATT=$(ioreg -c AppleDeviceManagementHIDEventService -r -l | grep -i mouse -A 20 | grep BatteryPercent | cut -d= -f2 | cut -d' ' -f2) | |
KEYBOARD_BATT=$(ioreg -c AppleDeviceManagementHIDEventService -r -l | grep -i keyboard -A 20 | grep BatteryPercent | cut -d= -f2 | cut -d' ' -f2) | |
COMPARE=${1:-20} | |
if (( MOUSE_BATT < COMPARE )); then | |
osascript -e "display notification \"Mouse battery is at ${MOUSE_BATT}%.\" with title \"Mouse Battery Low\"" | |
fi | |
if (( KEYBOARD_BATT < COMPARE )); then | |
osascript -e "display notification \"Keyboard battery is at ${KEYBOARD_BATT}%.\" with title \"Keyboard Battery Low\"" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment