# Connect to Airpods and show battery status

**URL:** <https://community.folivora.ai/t/connect-to-airpods-and-show-battery-status/1921>\
**Category:** Setup/Preset Sharing\
**Tags:** touch-bar\
**Created:** [June 23, 2018, 10:08am UTC](https://community.folivora.ai/t/connect-to-airpods-and-show-battery-status/1921 "2018-06-23T10:08:47Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivan\_Thung](https://community.folivora.ai/user_avatar/community.folivora.ai/ivan_thung/32/520_2.png) [@Ivan\_Thung](https://community.folivora.ai/u/Ivan_Thung)\
**Post date:** [June 23, 2018, 10:08am UTC](https://community.folivora.ai/t/connect-to-airpods-and-show-battery-status/1921/1 "2018-06-23T10:08:47Z")

</div>

**Connect to Airpods and show battery status**  
[CheckAirPods.json](https://community.folivora.ai/uploads/default/original/1X/374a0882bf3e0de29301a4540d54e2ec3342b64d.json) (2.2 MB)

I pulled together some scripts to create a button for the Airpods.

- pressing the button connects or disconnects the airpods.
- you will need to change the name to the name of your Airpods in the applescripts.

**Screenshots**  
How it looks when not connected.

 ![56](https://community.folivora.ai/uploads/default/original/1X/1c74387025abf50c0aeed92eef0eddca944f1cdb.png)

How it looks when connected.

 ![48](https://community.folivora.ai/uploads/default/original/1X/4f47533ba6b528f6617cf19c61f7351d9363780a.png)

The shellscript is from Duck: [https://blog.duklabs.com/airpods-power-in-touchbar/](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.

Hope it can be useful for some of you,  
I

---

<div class="post-metadata">

**Author:** ![jzhen](https://community.folivora.ai/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@jzhen](https://community.folivora.ai/u/jzhen)\
**Post date:** [July 20, 2018, 2:05am UTC](https://community.folivora.ai/t/connect-to-airpods-and-show-battery-status/1921/2 "2018-07-20T02:05:34Z")

</div>

Hi,

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:

1. Have another bluetooth device connected (like a mouse or keyboard) and make sure it's before your AirPods on the bluetooth list.
2. Have your AirPods second or third or anywhere after the first bluetooth device on the list and make sure it is not connected.
3. 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:"

---

<div class="post-metadata">

**Author:** ![cliophate](https://community.folivora.ai/letter_avatar_proxy/v4/letter/c/6bbea6/32.png) [@cliophate](https://community.folivora.ai/u/cliophate)\
**Post date:** [July 27, 2018, 1:18pm UTC](https://community.folivora.ai/t/connect-to-airpods-and-show-battery-status/1921/3 "2018-07-27T13:18:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kdhyde](https://community.folivora.ai/letter_avatar_proxy/v4/letter/k/df788c/32.png) [@kdhyde](https://community.folivora.ai/u/kdhyde)\
**Post date:** [July 30, 2018, 4:04pm UTC](https://community.folivora.ai/t/connect-to-airpods-and-show-battery-status/1921/4 "2018-07-30T16:04:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cliophate](https://community.folivora.ai/letter_avatar_proxy/v4/letter/c/6bbea6/32.png) [@cliophate](https://community.folivora.ai/u/cliophate)\
**Post date:** [July 30, 2018, 7:32pm UTC](https://community.folivora.ai/t/connect-to-airpods-and-show-battery-status/1921/5 "2018-07-30T19:32:08Z")

</div>

I found two. I replaced them. Anything elsw that needs to change?

What happens is it simply opens the context menu of the menubar for the Bluetooth icon. And that‘s it.

---

<div class="post-metadata">

**Author:** ![kdhyde](https://community.folivora.ai/letter_avatar_proxy/v4/letter/k/df788c/32.png) [@kdhyde](https://community.folivora.ai/u/kdhyde)\
**Post date:** [July 30, 2018, 7:45pm UTC](https://community.folivora.ai/t/connect-to-airpods-and-show-battery-status/1921/6 "2018-07-30T19:45:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cliophate](https://community.folivora.ai/letter_avatar_proxy/v4/letter/c/6bbea6/32.png) [@cliophate](https://community.folivora.ai/u/cliophate)\
**Post date:** [July 31, 2018, 6:00am UTC](https://community.folivora.ai/t/connect-to-airpods-and-show-battery-status/1921/7 "2018-07-31T06:00:34Z")

</div>

Oh, you are right. I did not see that. It now works. Thank you so much!

---

<div class="post-metadata">

**Author:** ![Ivan\_Thung](https://community.folivora.ai/user_avatar/community.folivora.ai/ivan_thung/32/520_2.png) [@Ivan\_Thung](https://community.folivora.ai/u/Ivan_Thung)\
**Post date:** [August 1, 2018, 8:39am UTC](https://community.folivora.ai/t/connect-to-airpods-and-show-battery-status/1921/8 "2018-08-01T08:39:28Z")

</div>

[Connect to Airpods\_v2.json](https://community.folivora.ai/uploads/default/original/1X/478b00a98ff968caf6a6da524458a2d6f0d4fb7c.json) (2.2 MB)

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.

---

<div class="post-metadata">

**Author:** ![Sahaj.Patel](https://community.folivora.ai/letter_avatar_proxy/v4/letter/s/46a35a/32.png) [@Sahaj.Patel](https://community.folivora.ai/u/Sahaj.Patel)\
**Post date:** [August 31, 2018, 12:10am UTC](https://community.folivora.ai/t/connect-to-airpods-and-show-battery-status/1921/9 "2018-08-31T00:10:10Z")

</div>

this version isnt working for me

---

<div class="post-metadata">

**Author:** ![Caliguvara](https://community.folivora.ai/user_avatar/community.folivora.ai/caliguvara/32/42570_2.png) [@Caliguvara](https://community.folivora.ai/u/Caliguvara)\
**Post date:** [November 20, 2018, 6:20pm UTC](https://community.folivora.ai/t/connect-to-airpods-and-show-battery-status/1921/10 "2018-11-20T18:20:12Z")

</div>

Hi guys,  
Is there any possibilities to get the batteries in two lines, one above the other (a bit like the music widget, playing Gorillaz right now)?

 ![25](https://community.folivora.ai/uploads/default/original/2X/b/b1f72c0fe5eb7e72076381ac67888a7709cbed50.png)  
My bar gets a little full, and I'd like to be the AirPods Widget as small as possible actually, but still always present 😉 Thanks !!

---

<div class="post-metadata">

**Author:** ![Caliguvara](https://community.folivora.ai/user_avatar/community.folivora.ai/caliguvara/32/42570_2.png) [@Caliguvara](https://community.folivora.ai/u/Caliguvara)\
**Post date:** [January 1, 2019, 5:35pm UTC](https://community.folivora.ai/t/connect-to-airpods-and-show-battery-status/1921/11 "2019-01-01T17:35:48Z")

</div>

Bringing this up again. Unfortunately my abilities of coding aren't good enough to do this myself, but a script finishing like

```
set LeftAirPod to "L: " & word 1 of Battery & "%"
set RightAirPod to "R: " & word 2 of Battery & "%"
return LeftAirPod & "
" & RightAirPod

```

At lest something like this works in a Preset for the Fan rpm, the result looks like this.  
 ![image](https://community.folivora.ai/uploads/default/original/2X/e/e69b68a1322abf10daef63f5a2cb6a5ca725f627.png)  
Any ideas?

---

<div class="post-metadata">

**Author:** ![machiz7888](https://community.folivora.ai/user_avatar/community.folivora.ai/machiz7888/32/5038_2.png) [@machiz7888](https://community.folivora.ai/u/machiz7888)\
**Post date:** [January 8, 2019, 10:34pm UTC](https://community.folivora.ai/t/connect-to-airpods-and-show-battery-status/1921/12 "2019-01-08T22:34:10Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Wao](https://community.folivora.ai/user_avatar/community.folivora.ai/wao/32/9599_2.png) [@Wao](https://community.folivora.ai/u/Wao)\
**Post date:** [January 15, 2020, 2:45pm UTC](https://community.folivora.ai/t/connect-to-airpods-and-show-battery-status/1921/13 "2020-01-15T14:45:47Z")

</div>

Sorry, I'm just new BTT guy. How could I import/use this json to my BTT?

Thanks

---

<div class="post-metadata">

**Author:** ![Caliguvara](https://community.folivora.ai/user_avatar/community.folivora.ai/caliguvara/32/42570_2.png) [@Caliguvara](https://community.folivora.ai/u/Caliguvara)\
**Post date:** [January 15, 2020, 3:04pm UTC](https://community.folivora.ai/t/connect-to-airpods-and-show-battery-status/1921/14 "2020-01-15T15:04:07Z")

</div>

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! 🙂

---

<div class="post-metadata">

**Author:** ![Wao](https://community.folivora.ai/user_avatar/community.folivora.ai/wao/32/9599_2.png) [@Wao](https://community.folivora.ai/u/Wao)\
**Post date:** [January 17, 2020, 12:31pm UTC](https://community.folivora.ai/t/connect-to-airpods-and-show-battery-status/1921/15 "2020-01-17T12:31:06Z")

</div>

Sorry for the late reply, Cali.

I tried the v2 json. Too bad, it doesn't work on Catalina.

Any news?

Thanks 😊

---

<div class="post-metadata">

**Author:** ![Caliguvara](https://community.folivora.ai/user_avatar/community.folivora.ai/caliguvara/32/42570_2.png) [@Caliguvara](https://community.folivora.ai/u/Caliguvara)\
**Post date:** [January 17, 2020, 1:49pm UTC](https://community.folivora.ai/t/connect-to-airpods-and-show-battery-status/1921/16 "2020-01-17T13:49:29Z")

</div>

![Widget](https://community.folivora.ai/uploads/default/original/2X/5/5a7ca26b6186c130bf24fd343171281a4cccc16a.png)  
I could offer you the Widget used by myself for the [PHoeNiX](https://community.folivora.ai/t/phoenix-preset-c3-update-for-catalina-including-a-working-airpods-widget/12075) Preset, @yuuiko in [AquaTouch](https://community.folivora.ai/t/v3-5-5-20-dec-aquatouch-supports-40-apps-websites-and-the-native-touchbar/1704), and (I think) @GoldenChaos in his [homonymous](https://community.folivora.ai/t/goldenchaos-btt-the-complete-touch-bar-ui-replacement/1281) preset.

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…).

Here is the widget: [AirPods Widget.json](https://community.folivora.ai/uploads/short-url/vcSDXZOq1ciQrRhWKdX290hhGAR.json) (63.7 KB)  
Here is the trigger: [Reset AirPods Widget.json](https://community.folivora.ai/uploads/short-url/jcUCogKJTlHUQOelAaGQjVeX1vV.json) (1.8 KB)

* * *

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à!

 ![Screenshot 2020-01-17 at 15.46.07](https://community.folivora.ai/uploads/default/original/2X/8/863ec40588c4cd820b96021fa3c5de4ac7c180e8.jpeg)

---

<div class="post-metadata">

**Author:** ![K2DesignLab](https://community.folivora.ai/user_avatar/community.folivora.ai/k2designlab/32/5468_2.png) [@K2DesignLab](https://community.folivora.ai/u/K2DesignLab)\
**Post date:** [January 17, 2020, 2:54pm UTC](https://community.folivora.ai/t/connect-to-airpods-and-show-battery-status/1921/17 "2020-01-17T14:54:33Z")

</div>

@Caliguvara Something like this?

 ![Touch Bar Shot 2020-01-17 at 8.49.37 AM](https://community.folivora.ai/uploads/default/original/2X/8/8628f4a4a4890304b993dd371e11bc7379eb2058.png)  
 ![Touch Bar Shot 2020-01-17 at 8.55.08 AM](https://community.folivora.ai/uploads/default/original/2X/a/a35484ceecfc1327626581f352c20989b0360f0a.png)

```
return "L " & batteryPercentLeft & "
" & "R " & batteryPercentRight
else
return "Not" & "
" & "Connected"
```

---

<div class="post-metadata">

**Author:** ![Caliguvara](https://community.folivora.ai/user_avatar/community.folivora.ai/caliguvara/32/42570_2.png) [@Caliguvara](https://community.folivora.ai/u/Caliguvara)\
**Post date:** [January 17, 2020, 10:59pm UTC](https://community.folivora.ai/t/connect-to-airpods-and-show-battery-status/1921/18 "2020-01-17T22:59:55Z")

</div>

Exactly 😉 your preset is the only one that I remember that shows the battery percentage of the case too. 😉
