Airpods Battery Level Script No Longer Works (Monterey?)

I have run the macro this way, but the error message remains the same:

I hope you don't mind if I provide my approach to solving this.

I would turn off the "Failure Aborts Macro" flag on the Search Variable action, then follow that statement with "If Action Result Condition is not OK then I would display the variable you are using in a Display Text action but make sure you place characters (eg, perhaps brackets) around the text's output so you can see if you have an extra spaces at the end of the variable. I do this a lot to troubleshoot similar problems.

1 Like

That's a mystery. I suspect that there are invisible characters filtered either by browser or the server. It happened to me before.

Can you try the following macro below and show us the result? If there are invisible characters, the python code may be able to catch them.

I have below in the code:


Your python interpreter might be in another directory. You will need to adjust accordingly.

Airpods Pro Battery Level - to Unicode.kmmacros (5.1 KB)

Click to see screenshot

The RegEx search does not have an end of string sign: $. Whatever follows would not matter. There must be something within the 21 % 42 % 35 % that causes the RegEx search to fail.

Fair enough. In that case, before displaying it, run the variable through the shell command "cat -v" so that you can see special characters show up.

@martin here is the result after running the macro:

CC:C9:5D:50:C9:86@@21 % 27 % 20 %

b'CC:C9:5D:50:C9:86@@21\\N{NO-BREAK SPACE}% 27\\N{NO-BREAK SPACE}% 20\\N{NO-BREAK SPACE}%'

b'CC:C9:5D:50:C9:86@@21\\xa0% 27\\xa0% 20\\xa0%'

It's clear now.
Your string has a NO-BREAK SPACE (\xa0) instead of a regular space. (My string does not have a space at all there.) When you paste it to the forum, the NO-BREAK SPACE is changed to a regular space.

You may add an action before the RegEx search action:

Please try this:

Airpods Pro Battery Level.kmmacros (10.4 KB)

Click to see screenshot

no chance... my MBP & KM still refuse :weary:

I ran your new macro and got the same/old error message again.


It is strange, because I have executed your first macro, which works for you, unchanged for me and then I get an error message.
This is the first time in all the years that a script makes such problems.

Thank you again for creating all the suggested solutions. You have something good with me.

@martin I can't explain it.... i have deleted from your macro \xa0 and from my

Result per copy & paste pasted again and all of a sudden it works:


Thanks again for your patience and time.

@Sleepy also thank you for your help.

1 Like

I don't quite understand what you're saying. Deleted \xa0 from where? From your previous post I saw \xa0 present in the RegEx search and replace action. The only difference is that the mouse cursor was blinking there.

But I'm glad that it finally works!

It's still a mystery to me that why it adds \xa0 to the returned string on your Mac but not on mine.

Mac: 2020 MBP13
macOS: Monterey (12.0.1)
KM Version: 10.0.1

1 Like

I don't understand it either.
If it was something about the browser... ok, but with your macro working for you, it should have worked for me.

For me:

MBP 2016
macOS: Monterey (12.0.1)
KM Version: 10.0.1
AirPods: 4A402

I noticed that now too. However, I had previously run the macro several times (as you sent it) and it had not worked.
I then deleted \xa0 and copied from my posted result and pasted it again. Hence the cursor in the gif. Sorry for the confusion.

I will try the macro on a friend. Let's see if your first version works or if I have the same problems.

Thanks again for your help :+1:

1 Like

Hey Guys,

When you have unusual data to post the forum please consider using this method.

Posting Unusual Data Strings to the Forum



Thanks, Chris! I've not thought of this method before~

1 Like

The script used to work for me on my old Intel MacBook Pro. Now with Monterey on my M1 Pro MacBook Pro, I no longer have the /Library/Preferences/ file.
Does anyone with an Apple Silicon Mac and MacOS Monterey have the same issue?

Try /Library/Preferences/ -- note the small "b" in "bluetooth". (That's on this Ventura install, I'm guessing Monterey is the same.)

Thanks for the suggestion. I tried it with /Library/Preferences/, but it still returns Domain /Library/Preferences/ does not exist.

Difficult to say what's up without seeing the command you're giving, but this certainly works in Ventura:

defaults read /Library/Preferences/

Do also check your Preferences folder:

ls -l /Library/Preferences | grep -i bluetooth case there's yet another variation in Monterey!

defaults read /Library/Preferences/

returns Domain /Library/Preferences/ does not exist


ls -l /Library/Preferences | grep -i bluetooth

returns nothing.

I use the macro below. It's working on my Mac.

One thing to note: You need to change the name of the Airpod to that on your Mac. Mine is "MY AirPods Pro" (the highlighted part below).

It is shown on your bluetooth device list:


Again, you will need to change it to the name of the Airpods on your Mac.

Here is the macro:

Airpods Pro Battery Life.kmmacros (4.7 KB)

🖼 Click to see screenshot