· 10 years ago · Aug 21, 2016, 01:52 AM
1#!/bin/bash
2#
3# Sound output switcher using PulseAudio,libnotify
4#
5# by Mickaël Quirin <eephyne[guess what put here]gmail.com
6# inspired by script done by Anton Veretenenko <anton[email sign]veretenenko.ru>
7#
8# Modified by alienjon <holy.smoking.floorboards.batman[ ]gmail.com>
9
10notify_show=1
11notify_delay=2000
12headset_card_num=1
13stereo_card_num=2
14
15
16active_device=`pacmd list-sinks | grep -i -E '\* index' | sed -r "s/^.*\* index: //"`
17
18if [ "$active_device" == "$headset_card_num" ]
19then
20pacmd "set-default-sink ${stereo_card_num}"
21test=`pacmd list-sink-inputs | grep -i -E 'index:'`
22
23while read -r line;
24do
25sink=(`echo $line | sed -r s/^.*index:\ //`)
26pacmd move-sink-input $sink ${stereo_card_num};
27done <<< $test
28
29 if [ $notify_show -eq 1 ]
30 then
31 notify-send -u normal -t $notify_delay -i gnome-sound-properties "Speakers Enabled" "Sound output switched to speakers"
32 fi
33else
34
35 pacmd "set-default-sink ${headset_card_num}"
36test=`pacmd list-sink-inputs | grep -i -E 'index:'`
37
38while read -r line;
39do
40sink=(`echo $line | sed -r s/^.*index:\ //`)
41pacmd move-sink-input $sink ${headset_card_num};
42done <<< $test
43
44 if [ $notify_show -eq 1 ]
45 then
46 notify-send -u normal -t $notify_delay -i gnome-sound-properties "Headset Enabled" "Sound output switched to headsets"
47 fi
48fi