Updating button icons results in the icon quickly disappearing

Describe the bug
Setting an icon via AppleScript for a button resets to without an icon on the latest alpha.
Affected input device (e.g. MacBook Trackpad, Magic Mouse/Trackpad, Touch Bar, etc.):
TouchBar

Screenshots
None.

Device information:

  • Type of Mac: MacBook Pro (13-inch, 2017, Four Thunderbolt 3 Ports)
  • macOS version: 10.14.5 (18F132)
  • BetterTouchTool version: 3.064

Additional information (e.g. StackTraces, related issues, screenshots, workarounds, etc.):
Switched to 3.05.

Note: Before bug reporting, please make sure you have the latest version of BetterTouchTool and that you have already tried to restart your system :-). If you encounter a crash, please attach a crash log from the macOS Console.app from the "User Diagnostic Reports" section.

set varUUID to "XXX"
set colorGREEN to "86, 193, 63, 255"
set colorBLUE to "6, 123, 195, 255"
set colorRED to "214, 35, 23, 255"
set colorYELLOW to "251, 219, 66, 255"
set icon1 to "~/Desktop/btt/timingBTT/icons/minus.icns"
set icon2 to "~/Desktop/btt/timingBTT/icons/plus.icns"
set icon3 to "~/Desktop/btt/timingBTT/icons/complete.icns"

tell application "TimingHelper"
	if not scripting support available then
		error "Scripting support requires a Timing Expert license. Please contact support via https://timingapp.com/contact to upgrade."
	end if
end tell
tell application "TimingHelper"
	set usageData to get time summary between (current date) and (current date)
	copy productivity score in usageData to savedResult
	set answer to (round (savedResult * 100) rounding down)
	delete usageData
tell application "BetterTouchTool"
	if answer > 0 and answer < 50 then
		update_touch_bar_widget varUUID background_color colorRED text answer icon_path icon1
	else if answer > 50 and answer < 70 then
		update_touch_bar_widget varUUID background_color colorYELLOW text answer icon_path icon2
	else if answer > 70 then
		update_touch_bar_widget varUUID background_color colorGREEN text answer icon_path icon3
	end if
end tell
end tell

Could you check the 3.065 alpha, I think I might already have fixed the issue yesterday.

3.065 alpha is not available, only 3.064

oops then I forgot to upload it yesterday :smiley: one moment, I'll check.

1 Like

It's now building & uploading, should be available in about 10 minutes.

One thing to note: update_touch_bar_widget will only update the current display value. If the script that is assigned to the widget returns a new value (e.g. when it's running periodically), then this will again override that data.

I'm not sure I'm understanding what you mean.

If you're referring to if its assigned in BTT then it is not. I make sure to click the "reset arrow" so that the color/icon/text assignments are all done programmatically.

In this case, its always showing just the value and no icons. (but only on 3.064).

Thank you for the quick response and all your work.

Ok, then I think it will work.

But could you copy & paste your widget here? I think there might be a more efficient way to implement it if I understood correctly.

//edit: 3.065 is online now.

Still same issue unfortunately.

[
  {
    "BTTWidgetName" : "timing",
    "BTTTriggerType" : 639,
    "BTTTriggerTypeDescription" : "Apple Script Widget",
    "BTTTriggerClass" : "BTTTriggerTypeTouchBar",
    "BTTPredefinedActionType" : 205,
    "BTTPredefinedActionName" : "Open Touch Bar Group With Name",
    "BTTOpenGroupWithName" : "timing_options",
    "BTTEnabled2" : 1,
    "BTTUUID" : "86E13506-5E7F-4571-B07F-C4C308F35F21",
    "BTTNotesInsteadOfDescription" : 0,
    "BTTEnabled" : 1,
    "BTTModifierMode" : 0,
    "BTTOrder" : 3,
    "BTTDisplayOrder" : 0,
    "BTTMergeIntoTouchBarGroups" : 1,
    "BTTTriggerConfig" : {
      "BTTTouchBarHideRecentlyUsedEmoji" : false,
      "BTTTouchBarAppleScriptString" : "set varUUID to \"86E13506-5E7F-4571-B07F-C4C308F35F21\"\nset colorGREEN to \"86, 193, 63, 255\"\nset colorBLUE to \"6, 123, 195, 255\"\nset colorRED to \"214, 35, 23, 255\"\nset colorYELLOW to \"251, 219, 66, 255\"\nset icon1 to \"~\/Desktop\/btt\/timingBTT\/icons\/minus.icns\"\nset icon2 to \"~\/Desktop\/btt\/timingBTT\/icons\/plus.icns\"\nset icon3 to \"~\/Desktop\/btt\/timingBTT\/icons\/complete.icns\"\n\ntell application \"TimingHelper\"\n\tif not scripting support available then\n\t\terror \"Scripting support requires a Timing Expert license. Please contact support via https:\/\/timingapp.com\/contact to upgrade.\"\n\tend if\nend tell\ntell application \"TimingHelper\"\n\tset usageData to get time summary between (current date) and (current date)\n\tcopy productivity score in usageData to savedResult\n\tset answer to (round (savedResult * 100) rounding down)\n\tdelete usageData\ntell application \"BetterTouchTool\"\n\tif answer > 0 and answer < 50 then\n\t\tupdate_touch_bar_widget varUUID background_color colorRED text answer icon_path icon1\n\telse if answer > 50 and answer < 70 then\n\t\tupdate_touch_bar_widget varUUID background_color colorYELLOW text answer icon_path icon2\n\telse if answer > 70 then\n\t\tupdate_touch_bar_widget varUUID background_color colorGREEN text answer icon_path icon3\n\tend if\nend tell\nend tell\n",
      "BTTTouchBarOnlyShowIcon" : false,
      "BTTTouchBarBringPlayerToFront" : 0,
      "BTTTouchBarItemPadding" : 0,
      "BTTTouchBarButtonColor" : "75.323769, 75.323769, 75.323769, 255.000000",
      "BTTTouchBarEmojiHideBackButton" : false,
      "BTTTouchBarItemPlacement" : 2,
      "BTTTouchBarAppleScriptStringRunOnInit" : true,
      "BTTTouchBarFontColorAlternate" : "255.000000, 255.000000, 255.000000, 255.000000",
      "BTTTouchBarAlwaysShowButton" : true,
      "BTTTouchBarHideWhenPaused" : 0,
      "BTTTouchBarScriptUpdateInterval" : 1000,
      "BTTTouchBarItemIconHeight" : 22,
      "BTTTouchBarBatteryHideOnCharging" : false,
      "BTTTouchBarButtonTextAlignment" : 3,
      "BTTTouchBarAlternateBackgroundColor" : "75.323769, 75.323769, 75.323769, 255.000000",
      "BTTTouchBarAppleScriptUsePath" : 0,
      "BTTTBWidgetWidth" : 400,
      "BTTTouchBarDefaultPlayer" : 0,
      "BTTTouchBarColorRegex" : "",
      "BTTTouchBarItemIconWidth" : 22,
      "BTTTouchBarButtonName" : "timing",
      "BTTTouchBarHideWhenNoPlayer" : false,
      "BTTTouchBarFontColor" : "255.000000, 255.000000, 255.000000, 255.000000",
      "BTTTouchBarButtonFontSize" : 10,
      "BTTTouchBarHideCover" : 0,
      "BTTTouchBarButtonCornerRadius" : 0,
      "BTTTouchBarFreeSpaceAfterButton" : 0
    }
  }
]

I included the wrong widget on accident my apologies. Its updated now.

Also yes that'd be fantastic. I'm a self-learned programmer and currently studying for an entrance exam so not too much time for messing with it unfortunately.

Although this seems to work ok here (are you sure the path to the icons is correct?), I think this is the issue: You have the script assigned directly to the widget. However script widgets always use the return value of the script to update the display value - your script however doesn't return anything.

You should change it not use the update_touch_bar_widget method but instead just return the value you need like this:

set pathvar to "/Users/andi/Downloads/IMG_4065.jpg"

return "{\"text\":\"newTitle\",                                                 
\"icon_path\": \"" & pathvar & "\",                                                
\"background_color\": \"255,85,100,255\",                                                 
\"font_color\": \"100,200,100,255\",                                                 
\"font_size\": 10}"

3.065 fixed it after reimporting triggers.

I'll definitely give it a shot soon after my exam in several weeks.

Your helps been great thank you again for your work and responsiveness.

How would one set the font family via the returned JSON string @Andreas_Hegenberg?