Dynamic Floating Menu Item Script executes, but menu item appearance never updates

Hi,

I’m trying to dynamically update a Floating Menu item based on the mute state of the macOS app “Telephone”.

on itemScript(itemUUID)
	try
		tell application "System Events"
			tell process "Telephone"
				
				set micMuted to false
				
				repeat with el in UI elements of window 1
					try
						if role of el is "AXStaticText" then
							
							set v to value of el
							
							if v is "Mikrofon stumm" then
								set micMuted to true
								exit repeat
							end if
							
						end if
					end try
				end repeat
				
				if micMuted then
					return "{BTTMenuItemBackgroundColor:'255,59,48,255',BTTMenuItemSFImage:'mic.slash'}"
				else
					return "{BTTMenuItemBackgroundColor:'52,199,89,255',BTTMenuItemSFImage:'mic.fill'}"
				end if
				
			end tell
		end tell
		
	on error
		return "{BTTMenuItemBackgroundColor:'120,120,120,255',BTTMenuItemSFImage:'questionmark'}"
	end try
end itemScript

The script executes correctly and returns different values depending on the mute state, but the Floating Menu item appearance never updates:

  • background color does not change
  • SF Symbol does not change
  • button just stays visually unchanged / black

Am I missing a required Floating Menu item type, rendering mode, or setting for dynamic appearance updates?

Thanks!

There are two issues:

  • the color parser currently expects spaces (I'll make that more flexible), instead you could also use hex values
  • BTTMenuItemSFImage does not exist

The easiest way to get the correct values is to configure an item to your needs, then copy it to a text editor. For example this should work (I don't have the telephone app to test though)

on itemScript(itemUUID)
	try
		tell application "System Events"
			tell process "Telephone"
				
				set micMuted to false
				
				repeat with el in UI elements of window 1
					try
						if role of el is "AXStaticText" then
							
							set v to value of el
							
							if v is "Mikrofon stumm" then
								set micMuted to true
								exit repeat
							end if
							
						end if
					end try
				end repeat
				
				if micMuted then
					return "{BTTMenuItemBackgroundColor:'255, 59, 48, 255',BTTMenuItemSFSymbolName:'mic.slash', BTTMenuItemIconType : 2}"
				else
					return "{BTTMenuItemBackgroundColor:'52, 199, 89, 255',BTTMenuItemSFSymbolName:'mic.fill', BTTMenuItemIconType : 2}"
				end if
				
			end tell
		end tell
		
	on error
		return "{BTTMenuItemBackgroundColor:'120, 120, 120, 255',BTTMenuItemSFSymbolName:'questionmark', BTTMenuItemIconType : 2}"
	end try
end itemScript

Awesome thanks. The spaces did the trick.

Any chance to change the icon via script?

Does the script I posted not change your icons?

Sorry I missed that part. It does change the icons. Works perfectly.

Thank you very much

1 Like