How to obtain/view the actual level of the external monitor volume (in Sketchybar, Shell Script) on MacOS?

I am trying to display the icon and the percentage of the EXTER MONITOR (Dell U4025QW) in Sketchybar on my MacBook Pro (M1). The aim is to show the volume of the accident and mute the condition in the bar.

What I want to achieve:

  • View the current volume of % and muted icon for my external Sketchybar monitor.
  • Have the volume update live as it changes.
  • When using the built -in display, it will return elegantly (ie the volume of the display of built -in speakers).

I use the following snippet in my Sketchybar pluger:

VOLUME=$(osascript -e "output volume of (get volume settings)")
MUTED=$(osascript -e "output muted of (get volume settings)")

source "$CONFIG_DIR/env.sh"
source "$CONFIG_DIR/icons.sh"

if ( "$MUTED" != "false" ); then
    ICON="${ICONS_VOLUME(0)}"
    VOLUME=0
else
    case ${VOLUME} in
        100) ICON="${ICONS_VOLUME(3)}" ;;
        (5-9)*) ICON="${ICONS_VOLUME(2)}" ;;
        (0-9)*) ICON="${ICONS_VOLUME(1)}" ;;
        *) ICON="${ICONS_VOLUME(2)}" ;;
    esac
fi

sketchybar -m \
    --set "$NAME" icon=$ICON \
    --set "$NAME" label="$VOLUME%"

When using the built -in MacBook display, it works perfectly. When using an external Dell Monitor, osascript Always returns missing value for volume gold 0Despite the volume of the HUD, the correct volume and keyboard volumes work.

Research and testing seems to be:

  • External monitors using Thunderbolt/USB audio output often do not expose their volume controls via MacOS scripting interfaces (such as AppleScript).
  • MacOS appears to “false” or cache a change of volume for these devices in the user interface, but do not report the actual volume of programmatically.
  • The state of mute is exposed and modest, but the percentage of volume is not.

Is there a well -known way, a tool or API that programmatically obtains the actual level of the external sound device Thunderbolt or USB (such as a monitor) on MacOS?

Leave a Comment