get_dock_badge_for stops getting correct data after a while

Describe the bug
I’m using code like these to check if Slack/Mail has unread every 2s and show alternative menubar icons.

if application "Slack" is running then
	tell application "BetterTouchTool"
		set badgeNumber to get_dock_badge_for "Slack" update_interval 1
	end tell
	if badgeNumber is not missing value then
		return "unread"
	end if
end if

return "read"

it works well initially, unread/read changes as app state changes. However, after a while it just stops updating. e.g. the current screenshot of dock:

Screenshot 2026-01-19 at 09.55.46

but script for Slack and Mail returns read and unread

Now if I restart BTT, everything works as expected again.


Affected input device (e.g. MacBook Trackpad, Magic Mouse/Trackpad, Touch Bar, etc.):


Screenshots
If applicable, add screenshots to help explain your problem. (You can just paste or drag them here)


Device information:

  • Type of Mac: M1
  • macOS version: 26.2
  • BetterTouchTool version: 6.067

Additional information (e.g. crash logs, related issues, etc.):

I’m seeing this as well. BTT seems to get “stuck” on the value that it first receives and won’t update until I restart BTT.

  • Quitting and relaunching the affected app doesn't have any effect, only restarting BTT.
  • Restarting the Dock doesn't help either, so this seems to be an internal BTT issue.

If I can get this working it would be a nice replacement for Doll.

Here’s the test script I’m using for my menu bar icon text (badgeNumber is called by the preset):

async function badgeNumber() {
  let num = await callBTT('get_dock_badge_for', {app: "Mail", update_interval: 5}) ?? 0;
  returnToBTT(JSON.stringify({
    'text': num,
    'hidden': (num == 0)
  }));
}

I've attached an export in case that's helpful:
mail_icon.bttpreset (2.0 KB)

Device information:

  • Type of Mac: M1
  • macOS version: 15.7.5
  • BetterTouchTool version: 6.306

@Andreas_Hegenberg Please let me know if there's any additional information I can provide to help troubleshoot this.

1 Like

I've come up with a workaround using dock-badge-counter. The Homebrew install wasn't working for me, so it may be necessary to compile the release version following instructions in the repo, then mv .build/release/dock-badge-counter /usr/local/bin/dock-badge-counter.

Once that's done, just grab Menu Bar Badges.bttpresetzip and customize as desired.

Tips

dock-badge-counter path
If installed via Homebrew, edit the DOCK_BADGE_COUNTER_PATH variable (it's currently set for manual install to /usr/local/bin):

const DOCK_BADGE_COUNTER_PATH = '/opt/homebrew/bin/dock-badge-counter'

Adding new apps
Each new app requires its own function within the shared external JavaScript file since (as far as I can tell) BTT doesn't currently allow passing parameters to scripts.

image

async function getBadgeCount_Messages() {
  return await getBadgeCount("Messages");
}

Badge refresh timing
Feel free to adjust CACHE_TIME_SEC in the script along with the Execute script every # seconds setting on the preset to your desired thresholds.