[Implemented in 2.814] Improving dock badge energy efficiency

Yup - here's the new script for a dock badge, which itself runs every 5s:

tell application "BetterTouchTool"
	try
		set dndEnabled to get_number_variable "SystemDoNotDisturbState"
	end try
end tell

if dndEnabled is 0 then
	tell application "BetterTouchTool"
		set badgeNumber to get_dock_badge_for "Google Chrome Canary" update_interval 5
	end tell
	if badgeNumber is not missing value then
		if badgeNumber contains "iPhone" then
			return "iPhone"
		else if badgeNumber contains "iPad" then
			return "iPad"
		else if badgeNumber contains "watch" then
			return "Watch"
		else if badgeNumber contains "Mac" then
			return "Mac"
		else
			return badgeNumber
		end if
	else
		return ""
	end if
else
	return ""
end if

I will try it later when I'm back at home. Maybe there is still some bug that prevents the update :slight_smile:

Your code looks good.

1 Like

It seems to specifically happen when the dock badge value changes to missing value, if that helps. BTT doesn't seem to be able to cope with going from having a badge to not having one. Updating from one value to another, however, works properly.

ah thanks for finding that! I forgot to delete them :slight_smile:
Will upload a new build in a few minutes.

2 Likes

Can confirm fixed in 2.817 :slight_smile:

1 Like

Oh how beautifully smooth

@GoldenChaos Just let me nab a few of those new apps... :eyes: aand it's perfect.

1 Like

@Andreas_Hegenberg

Just noticed an edge case:

I was trying to make a handoff badge for reminders, but it had 1 on it's badge, overriding the handoff value 'iPhone'

Is it possible to seperate the notification value from the handoff values?

Sorry I'm not sure I understand, could you post a screenshot of the Dock in this case?
(I'm not using handoff, not sure how that looks like).

Do you have the accessibility inspector app installed? That could show some additional info.
Instead of using the app name you can already use the URL of the dock item to get t he value:

My handoff valuse can display these:

'iPhone'
'iPad'
'watch'
'Mac'
a Notification Number.

In this situation (Handoff available, but have '1' badge):
13%20pm

The variable returns 1, overriding the handoff 'iPhone'. Normally if there is no badge it'll return details about the connected device, but because there is a notification, that is overrided with a 1.

With my code below, this means that the widget won't show up for handoff.

Code:

tell application "BetterTouchTool" to set LCL_DNDStatus to get_string_variable "DNDStatus"
if LCL_DNDStatus is "OFF" then
	tell application "BetterTouchTool" to set badgeNumber to get_dock_badge_for "Reminders" update_interval 5
	if badgeNumber is not missing value then
		if badgeNumber contains "iPhone" then
			return "{\"text\":\"πŸ“±\",\"font_size\": 15}"
		else if badgeNumber contains "iPad" then
			return "{\"text\":\"⬛️\",\"font_size\": 15}"
		else if badgeNumber contains "watch" then
			return "{\"text\":\"⌚️\",\"font_size\": 15}"
		else if badgeNumber contains "Mac" then
			return "{\"text\":\"πŸ–₯\",\"font_size\": 15}"
		else if application "Reminders" is running then
			return "{\"text\":\"" & badgeNumber & "\",\"font_size\": 15}"
		else
			return ""
		end if
	else
		return ""
	end if
else
	return ""
end if

In that case

get_dock_badge_for "file:///Applications/Reminders.app/" update_interval 5

Should still give you the correct badge number for the reminders app because the handoff badge doesn't have a URL.

I'm looking to get the handoff value, not the badge number.

Ideal way it'll work is that if handoff is availiable, it'll override any number value

Was that solution meant to force the badge number to appear?

Yes.

Ah I see. I don't think overriding the number value would be ideal as it would prevent various usecases. I'll just add a -handoff to the application name/url for these items.

2 Likes

Cool!

that -handoff is included in the latest alpha btw. (so use e.g. Reminders-handoff )

2 Likes

@Andreas_Hegenberg New handoff separation is working well!

@GoldenChaos my code if you're interested:

tell application "BetterTouchTool" to set LCL_DNDStatus to get_string_variable "DNDStatus"
if LCL_DNDStatus is "OFF" then
	tell application "BetterTouchTool"
		set badgeNumber to get_dock_badge_for "News" update_interval 3
		set handoffDevice to get_dock_badge_for "News-handoff" update_interval 3
	end tell
	if badgeNumber is not missing value and handoffDevice is missing value then
		if application "News" is running then
			return "{\"text\":\"" & badgeNumber & "\",\"font_size\": 15}"
        else 
            return ""
		end if
	else if handoffDevice is not missing value then
		if handoffDevice contains "iPhone" then
			return "{\"text\":\"πŸ“±\",\"font_size\": 15}"
		else if handoffDevice contains "iPad" then
			return "{\"text\":\"⬛️\",\"font_size\": 15}"
		else if handoffDevice contains "watch" then
			return "{\"text\":\"⌚️\",\"font_size\": 15}"
		else if handoffDevice contains "Mac" then
			return "{\"text\":\"πŸ–₯\",\"font_size\": 15}"
		end if
	else
		return ""
	end if
else
	return ""
end if
2 Likes

What's the difference between this and my existing handoff support? I'm slightly confused, haha ^^;

Your dock badge:

  • Prioritises notifications over handoff
  • Shows a number even if the app is not running

My Notification widget:

  • Prioritises handoff over notifications
  • Does not show notifications while the app isn’t running, but will
  • show handoff even if the app isn’t running
  • also wrote it more compact but idk if this makes it any more efficient :confused: oh well i did any way

Scenario:
Handoff showing in dock for reminders, reminders is not running but has a β€˜1’ dock badge too.

13%20pm
(it is running in there but pretend its not)

Mine will show the handoff
yours will get stuck at showing β€˜1’ even if handoff is available.

(my old one wouldn’t show at all, because the β€˜1’ blocked the handoff label from getting in, and the app isnt running)

1 Like

Ah, got it! Now I understand why an extra handoff thing was needed. I'll make the change to my dock badges :slight_smile:

Can I ask why do you need "update_interval 3" if you also have to Execute Script every x seconds with the Tigger Configuration in BTT?

Something about updating the internal database of badges or something... All I know is you need it there :man_shrugging: