Posted on 01-19-2012 04:09 PM
To create a smartgroup for notification?
Posted on 01-20-2012 02:48 PM
That's a great idea! Apparently on Lion there is a bug for the battery level reporting incorrectly on the mouse....I'm sure getting this command into a managed preference is possible one way or another:
For Apple keyboard:
ioreg -n "AppleBluetoothHIDKeyboard" | grep -i "batterypercent"
This would be a good topic for a feature request to post here on JAMF Nation.
Posted on 03-09-2012 03:30 PM
This only works if the recon runs while the device is connected, otherwise OS X doesn't know about it, so you can't query the battery status at all.
Here is one for the mouse, it returns an integer, value 111 if no device/battery was found.
#!/bin/sh
mouseLevel=`ioreg -n "BNBMouseDevice" | grep -i "batterypercent" | awk '{print $9}'`
#Check for greater than 0 string length, ie, there is such a device connected
if [ ${mouseLevel} > 0 ]; then
echo "<result>$mouseLevel</result>"
else
echo "<result>111</result>"
fi
Here is one for the keyboard:
#!/bin/sh
keyLevel=`ioreg -n "AppleBluetoothHIDKeyboard" | grep -i "batterypercent" | awk '{print $10}'`
#Check for greater than 0 string length, ie, there is such a device connected
if [ ${keyLevel} > 0 ]; then
echo "<result>$keyLevel</result>"
else
echo "<result>111</result>"
fi
Posted on 03-21-2012 07:21 AM
Anyone have any idea why this would work on some machines, but not all? I've got 4 conference rooms that have machines in them with Bluetooth mice and keyboards. I can get the ioreg commands to work for 2 of the 4 machines.
On the machines that do not report back a percentage, I've gone on and made sure OS X is seeing the devices (i.e. they are connected), and even seen the battery percentage in the Bluetooth menu. However the ioreg commands do not work.
All 4 machines are 10.6.8.
Any ideas?
Steve
Posted on 03-21-2012 07:47 AM
What happens on the machines if you run
ioreg -n "BNBMouseDevice" | egrep "o BNBM|BatteryPercent"
Posted on 03-21-2012 07:55 AM
Comes back blank. If I do:
ioreg | grep -i bnbmousedevice
or even:
ioreg | grep BNBMouseDevice
I get nothing. I've also tried searching for the Apple Keyboard:
ioreg | grep AppleBluetoothHIDKeyboard
And get nothing returned. It's like those values/classes do not exist in ioreg.
The same commands return values on the 2 machines that do work.
Steve
Posted on 03-21-2012 08:11 AM
How about
ioreg -l | grep -i mouse
failing that, does it show up in system profiler
system_profiler SPBluetoothDataType
Posted on 03-21-2012 08:18 AM
So yes, the word "mouse" shows up in ioreg (as expected) and I can see the following entry:
AppleBluetoothHIDMouse <class AppleBluetoothHIDMouse
However I still do not get a battery status using this:
ioreg -c AppleBluetoothHIDMouse | grep -i "batterystatus"
And, System Profiler shows the Bluetooth info, but there is no battery status in there.
I'm still curious as to why the original ioreg commands work on some machines, but not others.
Posted on 03-21-2012 08:29 AM
Cool, getting somewhere now. Looks like this mouse reports differently in ioreg. The class is AppleBluetoothHIDMouse and not BNBMouseDevice
Why did you change from "batterypercent" to "batterystatus"?
Try
ioreg -c "AppleBluetoothHIDMouse" | grep -i battery
Hopefully then you will see a list of battery entries, including the elusive percentage
Posted on 03-21-2012 08:44 AM
Hey, lookey there, there's some battery info.... :-)
I changed it because I was going from memory and had the wrong term.
Thanks for the help Sean!
Posted on 03-21-2012 09:02 AM
Try the below instead. If you need different device names, then add them in the declared array and they will automatically be added.
If you want different items to report (I've given some examples) then add a new 'theKey' followed by the function name 'ioreg'
#!/bin/bash
declare -a myDevices=(
'BNBMouseDevice'
'AppleBluetoothHIDKeyboard'
'AppleBluetoothHIDMouse'
);
function doioreg {
ioreg -c "${myDevices[$myCount]}" | grep -i ""$theKey"" | cut -d "=" -f 2
}
myCount=0
arrayLength=`echo ${#myDevices[@]}`
until [ $myCount -eq $arrayLength ]
do
theKey=product
doioreg
theKey=batterypercent
doioreg
theKey=DeviceName
doioreg
let myCount+=1
done
If you want a quick way to limit the output of ioreg to just the class you asked for, this will do it. Just change the class appropriately
ioreg -c "BNBMouseDevice" | grep """
Sean
Posted on 03-21-2012 03:18 PM
Just tidied it up and bit and made it more flexible, better output and enclosed in result for you. Second array so you can grab any keys you like. Easy to change for any class and keys in ioreg. Hope it's useful.
#!/bin/bash
echo -n "<result>"
declare -a myDevices=(
'BNBMouseDevice'
'AppleBluetoothHIDKeyboard'
'AppleBluetoothHIDMouse'
);
declare -a theKeys=(
'product'
'batterypercent'
'devicename'
);
function doioreg {
theValue=`ioreg -c "${myDevices[$myCount]}" | grep -i ""$theKey"" | cut -d "=" -f 2`
if [ "$theValue" ]
then
echo "$theKey:$theValue"
fi
}
myCount=0
arrayLength=`echo ${#myDevices[@]}`
until [ $myCount -eq $arrayLength ]
do
echo "${myDevices[$myCount]}"
insideCount=0
theKeyArrayLength=`echo ${#theKeys[@]}`
until [ $insideCount -eq $theKeyArrayLength ]
do
theKey="${theKeys[$insideCount]}"
doioreg
let insideCount+=1
done
let myCount+=1
done
echo "</result>"