38 lines
1.1 KiB
Bash
Executable File
38 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
SOURCE='@DEFAULT_AUDIO_SOURCE@'
|
|
SINK='@DEFAULT_AUDIO_SINK@'
|
|
|
|
case $1 in
|
|
source)
|
|
device=$SOURCE
|
|
;;
|
|
sink)
|
|
device=$SINK
|
|
;;
|
|
*)
|
|
echo "Invalid device: $1"
|
|
echo "Valid options are 'source' and 'sink'"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
print_device_info() {
|
|
# The node description seems to be the most useful value here, though different values are available.
|
|
# However, we'll strip the "Analog Stereo" part.
|
|
description=$(wpctl inspect "$device" | sed -n -e 's/.*node.description = "\(.*\) Analog Stereo"/\1/p')
|
|
|
|
# The output of a muted device is something like "Volume: 0.55", so we just nab the second field.
|
|
volume=$(wpctl get-volume "$device" | awk '/Volume/ { print $2 }')
|
|
|
|
# The output of a muted device is something like "Volume: 0.55 [MUTED]", so "true" if the third field is present, "false" otherwise.
|
|
muted=$(wpctl get-volume "$device" | awk '/Volume/ { print ($3 ? "true" : "false") }')
|
|
|
|
echo "{ \"description\": \"$description\", \"volume\": $volume, \"muted\": $muted }"
|
|
}
|
|
|
|
print_device_info
|
|
|
|
pactl --format=json subscribe | grep --line-buffered $1 | while read -r event; do print_device_info; done |