The shellscript is from Duck: https://blog.duklabs.com/airpods-power-in-touchbar/
Logo's are from the Noun project (Allen Wang).
Some of the other code I pulled together from some fora, can't really remember where tbh.
Thanks for this script. I really love it and I find it very useful!
While using this widget, I did find a small bug.
To replicate it:
Have another bluetooth device connected (like a mouse or keyboard) and make sure it's before your AirPods on the bluetooth list.
Have your AirPods second or third or anywhere after the first bluetooth device on the list and make sure it is not connected.
The widget will display 'Not Connected' instead of 'x'.
I believe this is a bug with your logic in looping. It seems like the script hits the if statement on the third line here and returns checkBattery() because the bluetooth devices before the AirPods are Connected: Yes.
repeat numberOfDevices times --loop through each devices checking for Connected string
if item counter of myList contains "Ivan's AirPods" 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
I don't have any experience writing Apple Script, but I might try to debug this on the weekend.
UPDATE:
Found the fix. For anybody using this widget in the future, there are three strings you will need to change.
Replace the two occurrences of "Ivan's AirPods" with "Your AirPod Name"
Replace the one occurrence of "name:" with "You AirPod Name:"
Am I right to understand that this automatically connects the AirPods with the Mac?
If yes, I can't get it to work. When I click on it, all it does is to open the Bluetooth pane in the menubar.
There's another instance of "Ivan's AirPods" in the AppleScript that is supposed to connect the AirPods automatically. Expand the settings for the trigger and edit the name "Ivan's AirPods" to your appropriate name and then it should work.
The third instance I’m talking about is in the trigger settings, accessed from the cog wheel settings icon to the right of the drop-down menu where you choose what the button does when it is pressed (should say “Run Apple Script (blocking)”). Different window from the two instances you already replaced.
I am happy that it was useful for you! I cleaned the code a little bit in the shell-script part, and removed some funny loops. Explanation: the display of the battery level is like this: 5% - 10%, where the first percentage represents the case, and the second one of the earpods -- trying to keep the button as small as possible.
Echoing this! I tried to take a look, I have no idea how this code works but would love to stack it. Also my case doesn't show up in the battery meter?
Download it. In BTT, navigate to the top right corner → presets → import → and navigate to The json
This discussion is heavily outdated though. If you're using Catalina there's a high risk that this won't work anymore. Give it a try though, and if it doesn't work I have another link for you!
Basically it will display your AirPods' battery levels one above the other, we all got rid of the battery level of the Case (I think though @K2DesignLab has a preset with all three values, I just don't find the link anymore…).
Import both .json files just like you did before (the trigger will appear in the triggers section don't worry if you don't see it the Touch Bar). Hold the widget in the TouchBar and write your AirPods name when asked (important: if you use the standard name like Wao's AirPods don't type it, but paste it from the System Settings → Bluetooth section - for any reason the ' used by apple is some other odd special character we didn't figure out yet).
Last but not least, check in BTT and give the widget the option to connect to your AirPods when hit Voilà!