How to hide an AppleScript Menubar Item based on script result?

Clearing text/sf_symbol/icon only makes it smaller but still takes some space and clickable.

returning an empty string from your script will hide it :slight_smile:

(you could also use the predefined action "Disable Configured Trigger" if you want to disable / enable from outside of your script)

1 Like

tried, returning an empty string seems only hide the icon but not the padding around it so it still takes space and clickable?

it should hide it competely, could you post your code or cooy & paste the whole item?

exported_triggers.bttpreset (2.1 KB)

captured screen when the area is clicked:

For me your script seems to work fine, but there is one issue:

if application "Messages" is running then
	tell application "BetterTouchTool"
		set badgeNumber to get_dock_badge_for "Messages" update_interval 1
	end tell
	if badgeNumber is not missing value then
		return "{'sf_symbol_name': 'left.bubble'}"
	end if
end if

return ""

You are returning sf_symbol_name "left.bubble". It should be "bubble.left".
Is it maybe entering this path and not showing the icon because it can not find it?

The if application "Messages" is running check can be problematic with Apple Script. Better use BTT's is_app_running with the bundle identifier com.apple.MobileSMS (funny that it still has this identifier after all these years)


tell application "BetterTouchTool"
	if is_app_running "com.apple.MobileSMS" then
		
		set badgeNumber to get_dock_badge_for "Messages" update_interval 1
		
		if badgeNumber is not missing value then
			return "{'sf_symbol_name': 'bubble.left'}"
		end if
	else 
	    return ""
	end if
end tell

Thanks for pointing out the typo. That’s said, after fixing the typo, it’s still same issue

exported_triggers.bttpreset (2.2 KB)

When there’s unread:

When there’s not:

Ah you are right, it doesn't happen here because I have disabled the padding for my menubar status items.

Let me check what's wrong.

Dang, I introduced an extra property for this use case but forgot to document it. Try to return this:

    return "{'hidden': true}"

Thanks, it’s better. Not clickable but still taking some space, as you can see when I move it around:

this is macOS tahoe right? I'll need to check whether anything changed there with the padding - maybe it is now enforced and setting the item size to 0 is not enough anymore.

(If you are on a Macbook with a notch I highly recommend to disable the padding because you can fit so many more items there without it :-))

Thanks, and yes, 26.2 (25C56).

Agree no need to over kill here, and I’ll mark this threads as resolved :slight_smile:

Trying to set some additional property that tries to hide the item if hidden: true is returned in 6.067. Maybe that helps