openbsd-dotfiles

Base configurations for my Openbsd desktop
git clone https://git.kausban.com/openbsd-dotfiles/raw/.git
Log | Files | Refs

dvol (1440B)


      1 #!/usr/bin/env bash
      2 set -euo pipefail
      3 
      4 # You can call this script like this:
      5 # $./dvol up
      6 # $./dvol down
      7 # $./dvol mute
      8 
      9 function send_notification {
     10     volume=$(sndioctl -n output.level)
     11     barlvl=$(echo "($volume + 0.005) * 256 / 8" | bc)
     12     # Make the bar with the special character ─ (it's not dash -)
     13     # https://en.wikipedia.org/wiki/Box-drawing_character
     14     bar=$(gseq -s "─" "$barlvl" | sed 's/[0-9]//g')
     15     # Send the notification
     16     dunstify -i audio-volume-medium -t 800 -r 2593 -u normal "$barlvl   $bar"
     17 }
     18 
     19 case $1 in
     20     up)
     21 		# Set the volume on (if it was muted)
     22 		# sndioctl output.mute=0
     23 		sndioctl output.level=+0.01 # Up the volume (+ 1%)
     24 		send_notification
     25 		;;
     26     down)
     27 		# sndioctl output.mute=0
     28 		sndioctl output.level=-0.01
     29 		send_notification
     30 		;;
     31     mute)
     32 		# dont actually run mute commands for server 0. Seems to work any way.
     33 		[ "$(sndioctl -n server.device)" = "0" ] || { [ "$(sndioctl -n output.mute)" = "1" ] && sndioctl -q output.mute=0 || sndioctl -q output.mute=1; }
     34 		
     35 		[ "$(sndioctl -n output.mute)" = "1" ] && dunstify -i audio-volume-muted -t 800 -r 2593 -u normal "Muted" \
     36 				|| send_notification
     37 		;;
     38     mic-mute)
     39 		[ "$(sndioctl -n input.mute)" = "1" ] && sndioctl input.mute=0 \
     40 				|| sndioctl input.mute=1
     41 		[ "$(sndioctl -n input.mute)" = "1" ] && dunstify -i mic -t 800 -r 2593 -u normal "Mic Muted" \
     42 				|| dunstify -i mic -t 800 -r 2593 -u normal "Mic Open"
     43 		;;	
     44 esac