Hide menubar icon until apple script returns true

Hey guys, I came up with an apple script that only shows battery percentage when battery level is below 11%. While it's above, I get an empty icon (between battery and control center). Is there any way to completely hide the element (or shrink it) until the percentage is shown?

CleanShot 2022-10-21 at 13.56.28@2x

Here's the script:

set batteryPercent to word 6 of paragraph 2 of (do shell script "pmset -g batt")

if batteryPercent is greater than "11" then

return ""

else if batteryPercent < "11" then

return batteryPercent & "%" & ""

end if

Any suggestions are welcome!

Did you see this?

Wow, no! Where's this?

Looks like it's the new advanced conditions feature. I don't have showBattertPercentage here :frowning:

I am also not sure how to use the advanced conditions feature with apple scripts, there's no such button

Am I doing something wrong?

Another issue I found is that if I keep this invisible element, menubar icons start jumping around any time. I press a modifier key.
CleanShot 2022-10-21 at 19.54.33

Modifier based visibility is set to this:

Are you trying to do this with the Notch Bar or with the standard menubar?

It's an Apple Script icon on the standard menubar.

Unfortunately I think I haven't added a good way to hide the Apple Script icons based on the script output yet. I'll check if this can be added easily.

That would be awesome! However, I think the issue is in icon itself changing its size (margin) on modifier key press. Here it's prominent:
CleanShot 2022-10-21 at 20.11.57

Maybe it could be possible to set a fixed with value to the menubar items? I know we can set icon width, but what about the fixed width for the button itself?

Allowing a fixed size would be easy, I'll add that with the next alpha.

I also just found where the jumping is coming from (if "always run when widget becomes visible" it's doing a relayout when the modifier keys are pressed). I'll fix that.

1 Like

Sounds perfect, thank you so much!

Hey there, just installed the latest alpha but the issue persists.

ah sorry, didn’t get to this yet. One of the next alphas :wink:

1 Like