I have no idea. I unfortunately don't owe any so I'm unable to code something for it It's possible though that this Script works fine for Battery Levels. This code here might not be compatible with Catalina btw, I'll post an update in half an hour or so.
Ok. Please paste this Apple Script below to your trigger and tell me if it works
return checkStatus()
on checkStatus()
set LclAirPodsName to "NAME_OF_YOUR_AIRPODS"
--ATTENTION If you use the "classic" name of the AirPods (like Caliguvara's AirPods) please do NOT type the name in the Window when asked! Instead, go to System Preferences… → Bluetooth select the device and copy the name there in order to paste it in BTT when asked to. The name looks like it contains a simple ' but it seems to be some other character, so your AirPods won't be found if you type it. If your AirPods have any other name (like AirMusic) just go ahead and type their name.
set myString to do shell script "system_profiler SPBluetoothDataType"
--initial check if AirPods are not even there
if myString does not contain LclAirPodsName then
display notification "Your AirPods are not connected." with title "AirPods Battery Check"
else
--find out if connected/disconnected
set AppleScript's text item delimiters to "name:"
set myList to the text items of myString --each item of mylist is now one of the devices
set numberOfDevices to count of myList
set counter to 1
repeat numberOfDevices times --loop through each devices checking for Connected string
if item counter of myList contains LclAirPodsName then
if item counter of myList contains "Connected: Yes" then
return checkBattery()
else if item counter of myList contains "Connected: No" then
display notification "Your AirPods are not connected." with title "AirPods Battery Check"
else
display notification "Error Parsing" with title "AirPods Battery Check" --this shouldn't happen
end if
end if
set counter to counter + 1
end repeat
end if
end checkStatus
on checkBattery()
set OUTPUT1 to do shell script "
OUTPUT1='';
BLUETOOTH_DEFAULTS=$(defaults read /Library/Preferences/com.apple.Bluetooth);
SYSTEM_PROFILER=$(system_profiler SPBluetoothDataType);
MAC_ADDR=$(grep -b2 \"Minor Type: Headphones\"<<<\"${SYSTEM_PROFILER}\"|awk '/Address/{print $3}');
CONNECTED=$(grep -ia6 \"${MAC_ADDR}\"<<<\"${SYSTEM_PROFILER}\"|awk '/Connected: Yes/{print 1}');
BLUETOOTH_DATA=$(grep -ia6 '\"'\"${MAC_ADDR}\"'\"'<<<\"${BLUETOOTH_DEFAULTS}\");
BATTERY_LEVELS=(\"BatteryPercentCombined\" \"HeadsetBattery\" \"BatteryPercentSingle\" \"BatteryPercentRight\");
if [[ \"${CONNECTED}\" ]];
then
for I in \"${BATTERY_LEVELS[@]}\";
do
declare -x \"${I}\"=\"$(awk -v pat=\"${I}\" '$0~pat{gsub (\";\",\"\"); print $3}'<<<\"${BLUETOOTH_DATA}\")\";
[[ ! -z \"${!I}\" ]] &&
OUTPUT1=\"${OUTPUT}$(awk '/BatteryPercent/{print substr($0)}'<<<\"${I}\")${!I}%\";
done;
printf \"%s\" \"${OUTPUT1}\";
fi"
set OUTPUT2 to do shell script "
OUTPUT2='';
BLUETOOTH_DEFAULTS=$(defaults read /Library/Preferences/com.apple.Bluetooth);
SYSTEM_PROFILER=$(system_profiler SPBluetoothDataType);
MAC_ADDR=$(grep -b2 \"Minor Type: Headphones\"<<<\"${SYSTEM_PROFILER}\"|awk '/Address/{print $3}');
CONNECTED=$(grep -ia6 \"${MAC_ADDR}\"<<<\"${SYSTEM_PROFILER}\"|awk '/Connected: Yes/{print 1}');
BLUETOOTH_DATA=$(grep -ia6 '\"'\"${MAC_ADDR}\"'\"'<<<\"${BLUETOOTH_DEFAULTS}\");
BATTERY_LEVELS=(\"BatteryPercentCombined\" \"HeadsetBattery\" \"BatteryPercentSingle\" \"BatteryPercentLeft\");
if [[ \"${CONNECTED}\" ]];
then
for I in \"${BATTERY_LEVELS[@]}\";
do
declare -x \"${I}\"=\"$(awk -v pat=\"${I}\" '$0~pat{gsub (\";\",\"\"); print $3}'<<<\"${BLUETOOTH_DATA}\")\";
[[ ! -z \"${!I}\" ]] &&
OUTPUT2=\"${OUTPUT}$(awk '/BatteryPercent/{print substr($0)}'<<<\"${I}\")${!I}%\";
done;
printf \"%s\" \"${OUTPUT2}\";
fi"
if OUTPUT1 is " " then
display notification "Your AirPods are not connected." with title "AirPods Battery Check"
else
set BatteryLevel to "L: " & word 2 of OUTPUT2 & "%" & "
" & "R:" & word 2 of OUTPUT1 & "%"
end if
if BatteryLevel is "L: " & "
" & "R: " then
display notification "Your AirPods are not connected." with title "AirPods Battery Check"
else
display notification BatteryLevel
end if
end checkBattery
--thanks to @yyuuiko for the base of the code!
--thanks to @GoldenChaos for the great problemsolving idea for Catalina!
Just saw your reply. Don't have any GitHub Repo though. I think @GoldenChaos mentioned an AirPods Pro support recently. Didn't have the possibility to check it though, by lack of hardware
Sure, I guess so If @yuuiko agrees too, as my script is based on parts he/she wrote for the Touch Bar widget.
Hihi this got messy so I put this "quote" to keep the flow while reading
Just saw your reply. Don't have any GitHub Repo though. I think @GoldenChaos mentioned an AirPods Pro support recently. Didn't have the possibility to check it though, by lack of hardware
Sure, I guess so If @yuuiko agrees too, as my script is based on parts he/she wrote for the Touch Bar widget