Advertisement
TheAtomicAss

audio-control.sh

Mar 7th, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.12 KB | None | 0 0
  1. #!/bin/bash
  2. set +x
  3. #trap read debug
  4.  
  5. # v 1.0, built for yggdrasil-3
  6.  
  7. # This script handles a variety of different audio configurations, as requested by the window manager (Awesome)
  8.  
  9.  
  10. # Interfaces
  11.  
  12. #     These functions should automatically adjust the interface variable if the interface changes.
  13. #     This is especially a problem with SPK_FACE is it will change when the monitor is swapped.
  14.  
  15. MIC_VOL=6554  # This is 10%, also marked as base in Pavucontrol
  16. MIC_FACE=alsa_input.pci-0000_00_1b.0.`pactl list cards|awk -F ":" '/alsa_card.pci-0000_00_1b.0/{while (!match($0,"Active Profile")) getline;print $4;exit;}'`
  17. SPK_FACE=alsa_output.pci-0000_01_00.1.`pactl list cards|awk -F ":" '/alsa_card.pci-0000_01_00.1/{while (!match($0,"Active Profile")) getline;print $3;exit;}'`
  18. B326HK=alsa_output.pci-0000_01_00.1.hdmi-stereo-extra2
  19. B326HKS=output:hdmi-stereo-extra2
  20. PG279Q=alsa_output.pci-0000_01_00.1.hdmi-stereo
  21. PG279QS=output:hdmi-stereo
  22. NVIDIA_CARD=alsa_card.pci-0000_01_00.1
  23.  
  24. # Functions
  25. MUTE_MIC()
  26. (
  27.   pactl set-source-mute $MIC_FACE toggle;
  28.   IS_MUTED_MIC=`pactl list sources|awk '/'$MIC_FACE'/{while (!match($0,"Mute")) getline;print $2;exit;}'`
  29.   if [ $IS_MUTED_MIC = no ]
  30.     then
  31.       notify-send "Microphone" "Is Unmuted"
  32.     else
  33.       notify-send "Microphone" "Is Muted"
  34.   fi
  35. )
  36.  
  37. FIX_MIC()
  38. (
  39.   pactl set-source-volume $MIC_FACE $MIC_VOL;
  40.   notify-send "Microphone" "Volume set to $(VOL_MIC)"
  41. )
  42.  
  43. MON_WHICH()
  44. (
  45.   echo $SPK_FACE|awk -F "." '{print $4}'
  46. )
  47.  
  48. SWAP_SPK()
  49. (
  50.   if [ $SPK_FACE == "$B326HK" ]
  51.     then
  52.       pactl set-card-profile $NVIDIA_CARD $PG279QS
  53.       notify-send "Monitor Speakers" "Switched to PG279Q"
  54.   elif [ $SPK_FACE == "$PG279Q" ]
  55.     then
  56.       pactl set-card-profile $NVIDIA_CARD $B326HKS
  57.       notify-send "Monitor Speakers" "Switched to B326HK"
  58.     else
  59.       notify-send "Monitor Speakers" "Alternate output selected, ABORTING"
  60.   fi
  61.   #pactl # In progress
  62.   notify-send "Monitor Speakers" "Switched output to: $SPK_FACE"
  63. )
  64.  
  65. LOWR_SPK()
  66. (
  67.   pactl set-sink-volume $SPK_FACE -5%;
  68.   notify-send "Monitor Speakers" "Volume set to $(VOL_SPK)"
  69. )
  70.  
  71. RISE_SPK()
  72. (
  73.   pactl set-sink-volume $SPK_FACE +5%;
  74.   notify-send "Monitor Speakers" "Volume set to $(VOL_SPK)"
  75. )
  76.  
  77. MUTE_SPK()
  78. (
  79.   pactl set-sink-mute $SPK_FACE toggle;
  80.   IS_MUTED_SPK=`pactl list sinks|awk '/'$SPK_FACE'/{while (!match($0,"Mute")) getline;print $2;exit;}'`
  81.   if [ $IS_MUTED_SPK = no ]
  82.     then
  83.       notify-send "Monitor Speakers" "Is Unmuted"
  84.     else
  85.       notify-send "Monitor Speakers" "Is Muted"
  86.   fi
  87. )
  88.  
  89. # Volume tests
  90. VOL_MIC()
  91. (
  92.   pactl list sources|awk '/'$MIC_FACE'/{while (!match($0,"Volume")) getline; print $5; exit; }'
  93. )
  94.  
  95. VOL_SPK()
  96. (
  97.   pactl list sinks|awk '/'$SPK_FACE'/{while (!match($0,"Volume")) getline; print $5; exit; }'
  98. )
  99.  
  100. # Process input commands
  101. case $1 in
  102.         micmute)MUTE_MIC;;
  103.         miclkvl)FIX_MIC;;
  104.         spkmute)MUTE_SPK;;
  105.         spkvlup)RISE_SPK;;
  106.         spkvldn)LOWR_SPK;;
  107.         spkswap)SWAP_SPK;;
  108.               *)echo "Audio Control: No valid command specified";
  109.                 notify-send "Audio Control: Error" "No valid command specified";;
  110. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement