Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.25 KB | None | 0 0
  1. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  2. # GNU General Public License for more details.
  3.  
  4. # You should have received a copy of the GNU General Public License
  5. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  6.  
  7. #------------------------------------------------------------------------
  8.  
  9. # The second parameter overrides the mixer selection
  10. # For PulseAudio users, use "pulse"
  11. # For Jack/Jack2 users, use "jackplug"
  12. # For ALSA users, you may use "default" for your primary card
  13. # or you may use hw:# where # is the number of the card desired
  14. MIXER="default"
  15. [ -n "$(lsmod | grep pulse)" ] && MIXER="pulse"
  16. [ -n "$(lsmod | grep jack)" ] && MIXER="jackplug"
  17. MIXER="${2:-$MIXER}"
  18.  
  19. # The instance option sets the control to report and configure
  20. # This defaults to the first control of your selected mixer
  21. # For a list of the available, use `amixer -D $Your_Mixer scontrols`
  22. SCONTROL="${BLOCK_INSTANCE:-$(amixer -D $MIXER scontrols |
  23.                  sed -n "s/Simple mixer control '\([A-Za-z ]*\)',0/\1/p" |
  24.                  head -n1
  25.                )}"
  26.  
  27. # The first parameter sets the step to change the volume by (and units to display)
  28. # This may be in in % or dB (eg. 5% or 3dB)
  29. STEP="${1:-4%}"
  30.  
  31. #------------------------------------------------------------------------
  32.  
  33. capability() { # Return "Capture" if the device is a capture device
  34.   amixer -D $MIXER get $SCONTROL |
  35.     sed -n "s/  Capabilities:.*cvolume.*/Capture/p"
  36. }
  37.  
  38. volume() {
  39.   amixer -D $MIXER get $SCONTROL $(capability)
  40. }
  41.  
  42. format() {
  43.   perl_filter='if (/.*\[(\d+%)\] (\[(-?\d+.\d+dB)\] )?\[(on|off)\]/)'
  44.   perl_filter+='{CORE::say $4 eq "off" ? "MUTE" : "'
  45.   # If dB was selected, print that instead
  46.   perl_filter+=$([[ $STEP = *dB ]] && echo '$3' || echo '$1')
  47.   perl_filter+='"; exit}'
  48.   perl -ne "$perl_filter"
  49. }
  50.  
  51. #------------------------------------------------------------------------
  52.  
  53. case $BLOCK_BUTTON in
  54.   3) amixer -q -D $MIXER sset $SCONTROL $(capability) toggle ;;  # right click, mute/unmute
  55.   4) amixer -q -D $MIXER sset $SCONTROL $(capability) ${STEP}+ unmute ;; # scroll up, increase
  56.   5) amixer -q -D $MIXER sset $SCONTROL $(capability) ${STEP}- unmute ;; # scroll down, decrease
  57. esac
  58.  
  59. volume | format
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement