AirPods Information and connection for Macs without TouchBar 🥳

Hi you all,

So, for quite a time now the compact AirPods widget with user friendly setup is out now, natively integrated into my own Preset as well as @yuuiko's AquaTouch.
45
This thing works great, allowing you to connect your AirPods without big setup trouble like before.

And now, I'm glad to tell you that the script is adapted to make it work without the Touch Bar :partying_face:

So, a two finger slide down (starting outside the trackpad) checks the AirPods status. This is what happens if they are disconnected.


And once they are connected…

If you disconnect them for any reason you'll get a little confirmation notification.

Voilà. Overall no big deal, just finally a solution for those who would like to display these information for any reason outside of the Touchbar :slightly_smiling_face:

If you import this through the Preset in BTT the actions should appear at the top of the list in the Trackpad section.

Have a super great time everybody!!
AirPods Status.json (10.8 KB)

What about airpods pro ?

1 Like

I have no idea. I unfortunately don't owe any so I'm unable to code something for it :confused: 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, Do you have a github repo ? I can add support for Aipods Pro and do a push request.

Ok. Please paste this Apple Script below to your trigger and tell me if it works :slightly_smiling_face:

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 :wink:

Sure, I guess so :man_shrugging:t4: If @yuuiko agrees too, as my script is based on parts he/she wrote for the Touch Bar widget.

1 Like

Alright, thank you very much, Is it ok for you if I create a github repo with this ?

Hihi this got messy so I put this "quote" to keep the flow while reading :stuck_out_tongue:


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 :wink:

Sure, I guess so :man_shrugging:t4: If @yuuiko agrees too, as my script is based on parts he/she wrote for the Touch Bar widget

Imprint | Privacy Policy