Created
January 12, 2022 11:30
-
-
Save un-def/f8f00d532ee72464629c16feda297165 to your computer and use it in GitHub Desktop.
Switch between two PulseAudio sinks
This file contains 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 | |
INTEGRATED='pci-0000_0c_00.4' | |
VIDEOCARD='pci-0000_0a_00.1' | |
TRAY_APP='volumeicon' | |
NOTIFICATION_SUMMARY='Audio Output' | |
die() { | |
notify-send "${NOTIFICATION_SUMMARY}" "${1}" -i audio-volume-muted -t 3000 | |
exit 1 | |
} | |
integrated='' | |
videocard='' | |
for sink in $(pacmd list-sinks | grep -oP '(?<=name: <)[^>]+'); do | |
case ${sink} in | |
*"${INTEGRATED}"*) integrated=${sink};; | |
*"${VIDEOCARD}"*) videocard=${sink};; | |
esac | |
done | |
if [ -z "${integrated}" ] || [ -z "${videocard}" ]; then | |
die 'Failed to inspect' | |
fi | |
if [ "$(pactl get-default-sink)" = "${integrated}" ]; then | |
sink=${videocard} | |
msg='Display' | |
else | |
sink=${integrated} | |
msg='Speakers' | |
fi | |
if ! pactl set-default-sink "${sink}"; then | |
die 'Failed to switch' | |
fi | |
notify-send "${NOTIFICATION_SUMMARY}" "${msg}" -i audio-volume-high -t 2000 | |
killall -e ${TRAY_APP} 2> /dev/null | |
${TRAY_APP} & | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The reason why we have to restart
volumeicon
: Maato/volumeicon#49