21 lines
622 B
Bash
Executable File
21 lines
622 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# Read audio volume & mute state
|
|
volume=50
|
|
muted=false
|
|
|
|
if command -v pactl &>/dev/null; then
|
|
vol_str=$(pactl get-sink-volume @DEFAULT_SINK@ 2>/dev/null | grep -Po '[0-9]+(?=%)' | head -n 1)
|
|
if [ -n "$vol_str" ]; then
|
|
volume=$vol_str
|
|
fi
|
|
mute_str=$(pactl get-sink-mute @DEFAULT_SINK@ 2>/dev/null)
|
|
if echo "$mute_str" | grep -q "yes"; then
|
|
muted=true
|
|
fi
|
|
elif command -v pamixer &>/dev/null; then
|
|
volume=$(pamixer --get-volume 2>/dev/null || echo 50)
|
|
muted=$(pamixer --get-mute 2>/dev/null || echo false)
|
|
fi
|
|
|
|
echo "{\"volume\": $volume, \"muted\": $muted}"
|