Sanity Check?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 07-28-2014 08:29 AM
Hey all,
I found a Bash script that checks the Bluetooth Keyboard/Mouse/Trackpad
When I run it, get different Battery Level percentages from the shell's output vs what the Mac says in System Profiler and the Bluetooth Menu.
It's been driving me nuts. Could it be something in the script that is doing the math wrong (if that is possible?)
It's a complicated script, for me at least, so I don't know how to debug something like this. Thought maybe if someone can try running the script and see.
This is the source of the original script.
http://www.macosxtips.co.uk/geeklets/system/battery-status-for-apple-wireless-keyboard-mouse-and-trackpad/
I needed to comment some lines out for the trackpad and added and sendEmail way on the bottom.
Thanks in advance as always!!
#!/bin/sh
KeyboardPercent=`ioreg -c AppleBluetoothHIDKeyboard | grep BatteryPercent | sed 's/[a-z,A-Z, ,|,",=]//g' | tail -1 | awk '{print $1}'`
typeset -i b=5
echo "Battery:
Keyboard: c"
if [ ${#KeyboardPercent} = 0 ]
then
echo "Disconnectedc"
else
if [ $KeyboardPercent -lt 11 ]
then
echo "�33[1;31mc"
else
echo "�33[0mc"
fi
while [ $b -le $KeyboardPercent ]
do
echo "|c"
b=`expr $b + 5`
done
while [ $b -le 100 ]
do
echo "�33[1;37m|�33[0mc"
b=`expr $b + 5`
done
echo "�33[0m $KeyboardPercent%c"
##unset KeyboardPercent
unset b
fi
echo "�33[0m
Mouse: c"
MousePercent=`ioreg -c BNBMouseDevice | grep BatteryPercent | sed 's/[a-z,A-Z, ,|,",=]//g' | tail -1 | awk '{print $1}'`
if [ ${#MousePercent} = 0 ]
then
echo "Disconnectedc"
else
if [ $MousePercent -lt 11 ]
then
echo "�33[1;31mc"
else
echo "�33[0mc"
fi
typeset -i b=5
while [ $b -le $MousePercent ]
do
echo "|c"
b=`expr $b + 5`
done
while [ $b -le 100 ]
do
echo "�33[1;37m|�33[0mc"
b=`expr $b + 5`
done
echo "�33[0m $MousePercent%c"
##unset MousePercent
unset b
fi
#echo "�33[0m
Trackpad: c"
#TrackpadPercent=`ioreg -c BNBTrackpadDevice | grep BatteryPercent | sed 's/[a-z,A-Z, ,|,",=]//g' | tail -1 | awk '{print $1}'`
#if [ ${#TrackpadPercent} = 0 ]
#then
# echo "Disconnectedc"
#else
# if [ $TrackpadPercent -lt 11 ]
# then
# echo "�33[1;31mc"
# else
# echo "�33[0mc"
# fi
# typeset -i b=5
# while [ $b -le $TrackpadPercent ]
# do
# echo "|c"
# b=`expr $b + 5`
# done
# while [ $b -le 100 ]
# do
# echo "�33[1;37m|�33[0mc"
# b=`expr $b + 5`
# done
# echo "�33[0m $TrackpadPercent%c"
##unset TrackpadPercent
# unset b
#fi
## Pat added this. If either battery level drops below 2%, it will send an email.
if [[ "$KeyboardPercent" -lt "2" ]] || [[ "$MousePercent" -lt "2" ]]
then
/usr/local/bin/sendEmail -f battTest@wk.com -t pat.camporeale@wk.com -s 10.1.3.33 -u "Batt Status" -m "Keyboard Battery Percent: $KeyboardPercent
Mouse Battery Percent: $MousePercent
"
else
unset KeyboardPercent
unset MousePercent
unset TrackpadPercent
fi
