Connect to Airpods and show battery status

touch-bar

#1

Connect to Airpods and show battery status
CheckAirPods.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.

How it looks when connected.

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.

Hope it can be useful for some of you,
I


Anki Flashcards
#2

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

#3

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.


#4

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.


#5

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.


#6

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.


#7

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


#8

Connect to Airpods_v2.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.


#9

this version isnt working for me


#10

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)?


My bar gets a little full, and I'd like to be the AirPods Widget as small as possible actually, but still always present :wink: Thanks !!