Skip to content

Instantly share code, notes, and snippets.

@gonzalo123
Created August 1, 2019 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gonzalo123/20c125f7421ad4f7c920f4735c8757d8 to your computer and use it in GitHub Desktop.
Save gonzalo123/20c125f7421ad4f7c920f4735c8757d8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
PATH=/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/bin:/usr/sbin:/sbin
# actual battery level
BATT=`ioreg -c AppleDeviceManagementHIDEventService -r -l | grep -i mouse -A 20 | grep BatteryPercent | cut -d= -f2 | cut -d' ' -f2`
# defaults to warn at 20%; accepts other number as 1st argument (useful for testing)
COMPARE=${1:-20}
if [ -z "$BATT" ]; then
echo 'No mouse found.'
exit 0
fi
if (( BATT < COMPARE )); then
osascript -e "display notification \"Mouse battery is at ${BATT}%.\" with title \"Mouse Battery Low\""
fi
@gonzalo123
Copy link
Author

*/15 * * * * cd ~ && bash ~/bin/mouse.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment