Skip to content

Instantly share code, notes, and snippets.

@gonzalo123 gonzalo123/mouse.sh
Created Aug 1, 2019

Embed
What would you like to do?
#!/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

This comment has been minimized.

Copy link
Owner Author

commented Aug 1, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.