Hm, it works for me here.
Try to paste this script and replace the YOUR_AIRPODS_NAMR_HERE with your AirPods name (twice).
Script
return checkStatus()
on checkStatus()
--set myString to button returned of (display dialog "Connected?" buttons {"Yes", "No"})
--set myString to "name: DR-BT101 Connected: " & myString
(*uncomment line below when done testing*)
set myString to do shell script "system_profiler SPBluetoothDataType"
--initial check if it's not even there
if myString does not contain "YOUR_AIRPODS_NAME_HERE" then
return false
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 "YOUR_AIRPODS_NAME_HERE" then
if item counter of myList contains "Connected: Yes" then
return checkBattery()
else if item counter of myList contains "Connected: No" then
return " "
else
display dialog "Error Parsing" --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"
return OUTPUT2 & "
" & OUTPUT1
end checkBattery
The output for the alternative icon should be space (" ").
If it still doesn't work, could you just copy the JSON of the file to your clipboard (right click on the widget) and send it to me in a private message? So I can take a look into it.
In two or three weeks (just let me pass my exams plz xD) you will also find and update of my Caliguvara C2 Preset, with a way better version of that widget done in collaboration with @yuuiko.
It will also be kinda integrated into an all new AirPlay widget I just finished, more to come with the Update to C3, I don't want to spoil anything