Change menubar icon when there are unread emails

I have a menubar item that has an action to open up GMail in Chrome. Works great! The Icon I use on the menubar is a SF Symbol called "envelope".

What do I need to do to make the icon "envelope.badge" when I have unread emails in GMail?

Thanks!

You would need a script that can check whether you have unread emails. This script would need to be run by BTT regularly.

I'm sure this could be done via the gmail API or imap, but without programming knowledge it will be hard to achieve (unless you can find a ready to use script on google)

Thank you Andreas. So, let's say we have this script, where should I add it? Where is the logic to change the menubar icon?

You would need to use one of the scriptable menubar items, these allow you to add a script and show different icons/colors depending on the output: