summaryrefslogtreecommitdiff
path: root/dot-config/bspwm/scripts/bspvolume
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2024-06-03 19:56:39 +0800
committerlittleblack111 <littleblack11111@gmail.com>2024-06-03 19:56:39 +0800
commitca968c4e5040f1ff4b5b5e12d9312360d807dcc1 (patch)
tree9900920e8f566794560c1519678e344351d2803b /dot-config/bspwm/scripts/bspvolume
parent5f3deaff0bf006a1a353e57b82ad48c0e8f143bc (diff)
added submodules, change . -> dot (see man stow --dotfiles)
Diffstat (limited to 'dot-config/bspwm/scripts/bspvolume')
-rwxr-xr-xdot-config/bspwm/scripts/bspvolume81
1 files changed, 81 insertions, 0 deletions
diff --git a/dot-config/bspwm/scripts/bspvolume b/dot-config/bspwm/scripts/bspvolume
new file mode 100755
index 00000000..716c65b2
--- /dev/null
+++ b/dot-config/bspwm/scripts/bspvolume
@@ -0,0 +1,81 @@
+#!/usr/bin/env bash
+
+## Script to manage speaker volume on Archcraft.
+
+# Icons
+iDIR='/usr/share/archcraft/icons/dunst'
+notify_cmd='dunstify -u low -h string:x-dunst-stack-tag:obvolume'
+
+# Get Volume
+get_volume() {
+ echo "`pulsemixer --get-volume | cut -d' ' -f1`"
+}
+
+# Get icons
+get_icon() {
+ current="$(get_volume)"
+ if [[ "$current" -eq "0" ]]; then
+ icon="$iDIR/volume-mute.png"
+ elif [[ ("$current" -ge "0") && ("$current" -le "30") ]]; then
+ icon="$iDIR/volume-low.png"
+ elif [[ ("$current" -ge "30") && ("$current" -le "60") ]]; then
+ icon="$iDIR/volume-mid.png"
+ elif [[ ("$current" -ge "60") && ("$current" -le "100") ]]; then
+ icon="$iDIR/volume-high.png"
+ fi
+}
+
+# Notify
+notify_user() {
+ ${notify_cmd} -i "$icon" "Volume : $(get_volume)%"
+}
+
+# Increase Volume
+inc_volume() {
+ [[ `pulsemixer --get-mute` == 1 ]] && pulsemixer --unmute
+ pulsemixer --max-volume 100 --change-volume +5 & get_icon && notify_user
+}
+
+# Decrease Volume
+dec_volume() {
+ [[ `pulsemixer --get-mute` == 1 ]] && pulsemixer --unmute
+ pulsemixer --max-volume 100 --change-volume -5 & get_icon && notify_user
+}
+
+# Toggle Mute
+toggle_mute() {
+ if [[ `pulsemixer --get-mute` == 0 ]]; then
+ pulsemixer --toggle-mute & ${notify_cmd} -i "$iDIR/volume-mute.png" "Mute"
+ else
+ pulsemixer --toggle-mute & get_icon && ${notify_cmd} -i "$icon" "Unmute"
+ fi
+}
+
+# Toggle Mic
+toggle_mic() {
+ ID="`pulsemixer --list-sources | grep 'Default' | cut -d',' -f1 | cut -d' ' -f3`"
+ if [[ `pulsemixer --id $ID --get-mute` == 0 ]]; then
+ pulsemixer --id ${ID} --toggle-mute && ${notify_cmd} -i "$iDIR/microphone-mute.png" "Microphone Switched OFF"
+ else
+ pulsemixer --id ${ID} --toggle-mute && ${notify_cmd} -i "$iDIR/microphone.png" "Microphone Switched ON"
+ fi
+}
+
+# Execute accordingly
+if [[ -x `which pulsemixer` ]]; then
+ if [[ "$1" == "--get" ]]; then
+ get_volume
+ elif [[ "$1" == "--inc" ]]; then
+ inc_volume
+ elif [[ "$1" == "--dec" ]]; then
+ dec_volume
+ elif [[ "$1" == "--toggle" ]]; then
+ toggle_mute
+ elif [[ "$1" == "--toggle-mic" ]]; then
+ toggle_mic
+ else
+ echo $(get_volume)%
+ fi
+else
+ ${notify_cmd} "'pulsemixer' is not installed."
+fi