NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Script update



On Thu, 26 Mar 2026 02:09:03 -0300
Isac Monção <isacmoncao%disroot.org@localhost> wrote:

> Hello everyone,
> 
> I created a script to help those who use a window manager and need a
> simple way to increase, decrease and get the current audio volume.
> Use and modify it as you wish. :)
> 

Thanks to DTB's suggestions, I modified the script and now it's much
more compact and simple. Here's a copy of it:

```sh
# Script to easily manipulate audio volume in NetBSD
# Author:           Isac Monção <isacmoncao%disroot.org@localhost>
# Last Modified:    26/03/2026 04:09 AM -03
# Requirements:     echo, mixerctl, sed, bc 
# License:          ISC
#
# Contributions:
#  - DTB <trinity@tebibyte.media>: Multiple if statements refactored
into a single case statement.
# 
# 頑張った
#
#!/bin/sh

INCREMENT="1"
MIXER_VARIABLE=outputs.master

usage() {
  echo "usage: vol up"
  echo "       vol down"
  echo "       vol get"
}

get_vol() {
  pattern="$MIXER_VARIABLE=[0-9][0-9]?[0-9]?,"

  current_vol=$(mixerctl "$MIXER_VARIABLE" | sed -E s"/$pattern//")
  perc_val=$(echo "(100 * $current_vol) / 248" | bc)
  echo "$perc_val%"
}

case "$1" in
   up)   mixerctl -w "$MIXER_VARIABLE+=$INCREMENT" ;;
   down) mixerctl -w "$MIXER_VARIABLE-=$INCREMENT" ;;
   get)  get_vol ;;
   *)    usage; exit 64;; # sysexits(3) EX_USAGE
esac


```
# Script to easily manipulate audio volume in NetBSD
# Author:           Isac Monção <isacmoncao%disroot.org@localhost>
# Last Modified:    26/03/2026 04:09 AM -03
# Requirements:     echo, mixerctl, sed, bc 
# License:          ISC
#
# Contributions:
#  - DTB <trinity@tebibyte.media>: Multiple if statements refactored into a single case statement.
# 
# é ?å¼µã?£ã??
#
#!/bin/sh

INCREMENT="1"
MIXER_VARIABLE=outputs.master

usage() {
  echo "usage: vol up"
  echo "       vol down"
  echo "       vol get"
}

get_vol() {
  pattern="$MIXER_VARIABLE=[0-9][0-9]?[0-9]?,"

  current_vol=$(mixerctl "$MIXER_VARIABLE" | sed -E s"/$pattern//")
  perc_val=$(echo "(100 * $current_vol) / 248" | bc)
  echo "$perc_val%"
}

case "$1" in
   up)   mixerctl -w "$MIXER_VARIABLE+=$INCREMENT" ;;
   down) mixerctl -w "$MIXER_VARIABLE-=$INCREMENT" ;;
   get)  get_vol ;;
   *)    usage; exit 64;; # sysexits(3) EX_USAGE
esac



Home | Main Index | Thread Index | Old Index