Changing ShellScript menubar icon based on script?

Can this just be

{"text":"Mic Off","icon_name":"mic.slash"}

Instead of having to input the SF Symbol in base 64 for example?

I initially wanted to make it toggle mute the mic (On Click) with this script:

#!/bin/bash

# Get the current input volume
current_volume=$(osascript -e 'input volume of (get volume settings)')

# Check if the input volume is 0
if [ "$current_volume" -eq 0 ]; then
    # Set the input volume to 100
    osascript -e 'set volume input volume 100'
    # Return JSON for "Mic on" with the mic icon
    echo '{"text":"Mic ✅","icon_name":"mic"}'
else
    # Set the input volume to 0
    osascript -e 'set volume input volume 0'
    # Return JSON for "Mic off" with the mic.slash icon
    echo '{"text":"Mic ❌","icon_name":"mic.slash"}'
fi

But I'm currently using this
#!/bin/bash current_volume=$(osascript -e 'input volume of (get volume settings)') [ "$current_volume" -eq 0 ] && echo "🔘" || echo "🟡"

Is there a setting to make it run the script on click? or should I add an action for it to work?

Thaanks :slight_smile:

The relevant variables are called:
"sf_symbol_name"
"sf_symbol_size"
"sf_symbol_weight"

(only sf_symbol_name is mandatory if I remember correctly)

To run on click, add the script as action as well. To update any item from some action you can use Apple Script like this:

tell application "BetterTouchTool" to update_menubar_item "6C734160-8671-4BB5-A891-E2C5031DF513" text "test" sf_symbol_name "mic.slash"

Amazing!

Thaanks

How can I change the icon and background colors?
sf_symbol_color?

image
Also, "sf_symbol_name" is not here..

Ah I need to update that.

The sf symbol color should follow the font color ("font_color") bakground color is "bakground_color"

tell application "BetterTouchTool" to update_menubar_item "E867528A-13CA-4297-8347-8892B633F7E8" sf_symbol_name "mic" font_color "255, 255, 0, 255"

Didn't work for me like this..

what happens when you execute it? If you haven't already configured a size for the sf icon, also provide that (sf_symbol_size )

Nothing happens, it doesn't work..

tell application "BetterTouchTool" to update_menubar_item "E867528A-13CA-4297-8347-8892B633F7E8" sf_symbol_name "mic" font_color "255, 255, 0, 255" sf_symbol_size 22

Same for this :point_up_2:

Full Script:

if input volume of (get volume settings) = 0 then
    set volume input volume 100
	tell application "BetterTouchTool" to update_menubar_item "E867528A-13CA-4297-8347-8892B633F7E8" sf_symbol_name "mic" font_color "255, 255, 0, 255" sf_symbol_size 22
else
    set volume input volume 0
	tell application "BetterTouchTool" to update_menubar_item "E867528A-13CA-4297-8347-8892B633F7E8" sf_symbol_name "mic.slash"
end if

Ah sorry, the font_color can indeed not be updated via apple script yet. I'll add that. The rest of your script seems to work fine

Got it!

Thaanks


What does Execute the script every = 0 in here mean?
And how can I stop it from running? Tried just removing the 0 and it's not working..

0 means it's not repeating, basically only triggers on initial load

When it's 0 for me here, it's basically instant.

I went to the sound settings, and when I change the volume of my mic, I see it change instantly in the menubar..

when I set it to 5, it updates every 5 sec, when I try to remove the 5, it goes back to 0 but keeps triggering every 5 sec

When I click the down arrow until it reaches 0, it's basically instant.

How can I stop it so it doesn't auto run..?

Any value less than or equal to 0 should cause it to only run on initialization. (I just confirmed by adding a say "hello" to the script

Maybe set it to -1 to be sure

I've disabled then enabled the trigger on BTT and now it's working as expected. :+1:
Looks like it was just getting stuck in the previous config of the trigger..