Posted on 11-06-2012 03:07 AM
Hi All.
I made a couple of extension attributes for querying the battery levels of Bluetooth Trackpads and Keyboards that may be useful to others.
Bluetooth Keyboard:
#!/bin/sh
kresult=`ioreg -r -c "AppleBluetoothHIDKeyboard" | grep -w BatteryPercent | sed 1d | awk '{print $4}' | sed s/"//g`
echo "<result>$kresult</result>"
Magic trackpad:
#!/bin/sh
tpBatLevel=`ioreg -r -c "BNBTrackpadDevice" | grep -w BatteryPercent | sed 1d | awk '{print $4}' | sed s/"//g`
echo "<result>$tpBatLevel</result>"
You can then create smart groups using these to generate notifications for low batteries. One thing to be aware of: If the keyboard or trackpad is asleep as the time the value is connected you will not get a value returned , so when creating a smart group you will need to add a is not and leave the field blank, otherwise you will get a lot of incorrect notifications.
This is also possible for bluetooth mice but I don't have one handy to find out the device name.
Posted on 05-06-2013 10:34 AM
Just happened to come across this and wanted to pass along my Mouse script with a slight modification to return output for our users who don't have bluetooth mice yet.
#!/bin/sh
mouseBatLevel=`ioreg -r -c "BNBMouseDevice" | grep -w BatteryPercent | sed 1d | awk '{print $4}' | sed s/"//g`
if [[ "${mouseBatLevel}" == "" ]] ; then
echo "<result>No Magic Mouse</result>"
else
echo "<result>$mouseBatLevel%</result>"
fi
exit 0
Posted on 05-29-2014 02:15 PM
You can then create smart groups using these to generate notifications for low batteries.
when I try to make a smart group with the bluetooth extension attribute, I get a error stating
"Bluetooth Mouse Battery is not a valid number"
Bluetooth Mouse Battery is the name of my extension attribute.
any suggestions?
thank you
Dan
Posted on 06-02-2014 11:30 AM
I had to comment out
#else # echo "<result>$mouseBatLevel%</result>"
and then I could get a smart group to report on the results.
Posted on 10-05-2015 01:42 PM
Has anyone noticed that what the command spits out is different than what the GUI says it is? I event looked up in System Information and it also doesn't match up with what the command spits out.