Custom Context Menu not showing BTT variables (AirPods Pro 3 Left/Right battery %)

Hi everyone,

I have a working Menu Bar Item that displays the case battery percentage of my AirPods Pro 3 in real time using a Shell Script + JSON output. That part works perfectly.

What I’m trying to achieve now: When I click on that icon in the menu bar, I want a small Custom Context Menu to appear just below it that shows:
Left: XX%
Right: XX%

I created a Run Apple Script (blocking) action that correctly sets two BTT string variables:

airpodsLeft
airpodsRight

When I click Run Script in the editor, it returns the correct values (:white_check_mark: Left: 80% | Right: 80%).

However, when I actually click the menu bar icon, the context menu either:

  • shows the literal text {airpodsLeft}% {airpodsRight}% instead of the real numbers, or
  • shows nothing at all.

Here are my current settings (see the three screenshots attached):

  1. The main Menu Bar Item configuration (Run Apple Script + Context Menu Item)
  2. The AppleScript that sets the variables (works when tested)
  3. The overall trigger setup (“Show Custom Context Menu (NEW)”)

I’ve tried:

  • Putting the script on the “Show Custom Context Menu” trigger itself
  • Putting the script as the first action before “Show Custom Context Menu”
  • Using {airpodsLeft}% in the Item Name field

Nothing makes the variables actually resolve in the popup menu.

Could someone explain the correct order / setup so that the AppleScript runs before the context menu is displayed and the variables are replaced with the real battery percentages?

Thanks a lot in advance :folded_hands:t3:



The standard context menu does not support variables (yet). You can however use a custom content script to generate the menu (you could also run the whole shell script from there):

//see https://docs.folivora.ai/docs/1108_simple_format.html
async function retrieveJSON() {

let airpodsLeft = await get_string_variable("airpodsLeft");
let airpodsRight = await get_string_variable("airpodsRight");

let items = [
{"title": `Left: ${airpodsLeft}`, "icon": "sfsymbol::airpod.left"},
{"title": `Right: ${airpodsRight}`, "icon": "sfsymbol::airpod.right"}
]; 

 return JSON.stringify(items);

}

awesome thanks you very much :folded_hands:t3: