#!/bin/sh -e dump="$(pw-dump)" devices="$(echo "$dump" | jq -r '.[].info.props | select((."api.alsa.pcm.stream"=="playback") or (."api.bluez5.connection"=="connected"))')" echo "$devices" descriptions="$(echo "$devices" | jq -r '."node.description"')" default_name="$(echo "$dump" | jq -r '.[] | select(.props."metadata.name"=="default") | .metadata.[] | select(.key=="default.audio.sink") | .value.name')" default_description="$(echo "$devices" | jq -r ". | select(.\"node.name\"==\"$default_name\") | .\"node.description\"")" picked_description="$(printf "%s\n%s" "$default_description" "$descriptions" | awk '!seen[$0]++' | dmenu -i -l 20 -p "Audio output")" [ -z "$picked_description" ] && exit 1 picked_id="$(echo "$devices" | jq -r ". | select (.\"node.description\"==\"$picked_description\") | .\"object.id\"")" [ -z "$picked_id" ] && exit 1 wpctl set-default "$picked_id"