Advertisement
antijingoist

Set maximum volume on a Linux computer

Dec 30th, 2024
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.61 KB | Source Code | 0 0
  1. #!/bin/bash
  2. maxVol=45
  3. maxSec=90
  4. interval=1
  5.  
  6. while true; do
  7.   sleep $interval
  8.   curV=$(amixer -c 0 sget Master | grep -Po "(\d\d)%" | grep -Po "\d*")
  9.   pcmV=$(amixer -c 0 sget  PCM | grep -Po "(\d\d)%" | grep -Po "\d*")
  10.   spkV=$(amixer -c 0 sget Speaker | grep -Po "(\d\d)%" | grep -Po "\d*")
  11.   if [ $curV ]; then
  12.     if [ $curV -gt $maxVol ]; then
  13.       resetV=$(amixer -c 0 sset Master $maxVol%)
  14.     fi
  15.     if [ $curV -gt $maxSec ]; then
  16.       resetV=$(amixer -c 0 sset PCM $maxSec%)
  17.     fi
  18.     if [ $spkV -gt $maxSec ]; then
  19.       resetV=$(amixer -c 0 sset Speaker $maxSec%)
  20.     fi
  21.   fi
  22.  
  23.  
  24. done &
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement