Display Notifications from Internet forum in the TouchBar

Hey together,

So, my idea is that when I get a mail from noreply@community.folivora.ai, the button that activates the link to this nice forum here shows an alternate icon (easy to do with apple script widgets).
What's harder is the how to do so?

I thought using an Apple Script like

tell application "Mail"
	tell (messages of mailbox "INBOX" of account "Google" whose read status is false and date received is (current date))
		set unread_messages to it
		repeat with each_message in unread_messages
			set the_sender to sender of each_message
			if the_sender contains "folivora" then
				return "New on BTT"
				set read status to true
			else
				return "Nothing happens on BTT"
			end if
		end repeat
		return unread_messages
	end tell
end tell
    end tell

I didn't want this to run every so and then, so I thought using rules in Mail.app with this script :

tell application "BetterTouchTool"
	update_touch_bar_widget "UUID"
end tell


This doesn't really work though :confused:

Several questions:

  1. Why?
  2. Do you know any other Mail program for macOS that supports Apple Script? I use a special email address for my forum inscriptions, and would like have it only on macOS, not on iOS.

Thanks for all your ideas and hints!

Oh I didn't know Mail could run Apple Script in rules. That's pretty amazing.

I think you can even get the full message right in the script. In your original script you can't use update_touch_bar_widget as that would require you to pass new text. What you would want is refresh_widget which will run its assigned script.

However something like this might be more performant (as the Apple Script that runs via the rule):

  using terms from application "Mail"
        on perform mail action with messages theMessages for rule theRule
            repeat with eachMessage in theMessages
                set theSender to sender of eachMessage
			    if the_sender contains "folivora" then
             
                   tell application "BetterTouchTool"
	                  update_touch_bar_widget "9990CE09-9820-4D67-9C52-8BABAB263056" text "New Message Arrived!"
                   end tell
                end if
            end repeat
        end perform mail action with messages
    end using terms from
1 Like

Thanks for the quick answer and the great idea! I'll ad a "mark email as read" point to the rule and hope it will be fine then! :slightly_smiling_face: Coming back on it here when I tested it

Unfortunately doesn't work either :sob:
The icon remains unchanged :frowning:

Tried with this rule:


Running that Apple Script

using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		repeat with eachMessage in theMessages
			set theSender to sender of eachMessage
			if the_sender contains "folivora" then
				tell application "BetterTouchTool"
					update_touch_bar_widget "11055E7D-829C-4B9B-A730-92E82D62FB85" text "New Message Arrived!"
				end tell
			end if
		end repeat
	end perform mail action with messages
end using terms from

With this TouchBar Widget.
Folivora.json (133.2 KB)

Help is welcome :wink:

Ok, so I looked deeper into this.
As the script only runs when triggered by Mail, I broke it down a bit to the essentials, resulting in

tell application "BetterTouchTool"
	update_touch_bar_widget "11055E7D-829C-4B9B-A730-92E82D62FB85" text "New Message Arrived!"
end tell

The hiccup is that the TouchBar icon does not change. If I display the text though, the script updates the widget with the correct text, so the script works as it should.


The Alternate Regrex is correct though. Could this be a #bug-reports with external scripting in BTT @Andreas_Hegenberg?


I also tried updating the icon of the widget through the Apple Script triggered by Mail with something like

tell application "BetterTouchTool"
	update_touch_bar_widget "11055E7D-829C-4B9B-A730-92E82D62FB85" text "New Message arrived!" icon_data "{\"Base64_icon_here\"}"
end tell

But this didn't work out either (the text was updated, the icon didn't care about my tells).

Edit: putting the code to icon_data "Base64_icon_here" worked out!