Sound Input Volume Widget / Script? Help needed

Hi Guys, I want a touch bar widget so I can toggle the sound input volume to 0 (basically mute mic). I want it to turn red when the input volume is 0 and turn green when it's not. (I've set the button background as green and alternate color as red).

The widget script in the widget config runs every 2 seconds to check if the volume is 0 or not via this script

try
	input volume of (get volume settings) = 0
end try

I wrote this as the action trigger which will set the volume to 0 or 60%

if input volume of (get volume settings) = 0 then
    set level to 60
else
	set level to 0
end if

set volume input volume level

I am noticing that sometimes this does not work. Meaning when I tap the touch bar button, it doesn't change color to red. Also, when this works, it is a little slow and takes a sec to update on which should only be expected if it auto-refreshes every 2 seconds, not when I tap the button right? Can anyone help me figure out a better approach to achieving this? I tried searching the forum but didn't find anything related.

Thanks

@Andreas_Hegenberg could you please take a quick look at this. Would appreciate it. Thanks