Created
August 1, 2019 12:22
-
-
Save gonzalo123/20c125f7421ad4f7c920f4735c8757d8 to your computer and use it in GitHub Desktop.
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 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
*/15 * * * * cd ~ && bash ~/bin/mouse.sh