Created
November 23, 2018 19:52
-
-
Save gonzoua/d42f13c5703f58a110415afb74b65d71 to your computer and use it in GitHub Desktop.
dialog(1)-based audio device selection for FreeBSD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
: ${DIALOG_CANCEL=1} | |
IFS=" | |
" | |
UNITS="" | |
for dev in $(cat /dev/sndstat | fgrep '(play'); do | |
unit=$(echo $dev | sed s/^pcm// | sed 's/:.*//') | |
description=$(echo $dev | sed 's/.*<//' | sed 's/>.*//') | |
UNITS="$UNITS $unit \"$description\"" | |
done | |
CURRENT=$(sysctl -n hw.snd.default_unit) | |
exec 3>&1 | |
SELECTION=`echo "${UNITS}" | xargs dialog --menu "Select audio device" 20 40 10 2>&1 1>&3` | |
if [ $? -eq $DIALOG_CANCEL ]; then exit 1; fi | |
exec 3>&- | |
if [ "${SELECTION}" != "${CURRENT}" ]; then | |
sysctl -q hw.snd.default_unit=${SELECTION} 2>&1 > /dev/null | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment