summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzachir <zachir@librem.one>2021-01-31 22:53:26 -0600
committerzachir <zachir@librem.one>2021-01-31 22:53:26 -0600
commitb2d4a269084c955ba27876b93cfc2cf915b0d8b7 (patch)
tree6756348c6f0773135ca531cd166f102db3b79f66
parentf6a937edb55f6c7551f08d9395ab1089706cc817 (diff)
Add support to get volume and mute
-rw-r--r--README.md11
-rwxr-xr-xvolsv10
2 files changed, 19 insertions, 2 deletions
diff --git a/README.md b/README.md
index b0dc96f..e139145 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,8 @@ Volsv is a POSIX-compliant shell script I wrote in 2020, and have been modifying
- Decreasing volume
- Toggling the interface mute
- Toggling the microphone mute\*
+- Getting the volume
+- Getting the mute state
in both pulseaudio and ALSA\*. Once I get OpenBSD and FreeBSD up and running, I will add those sound options too.
@@ -21,6 +23,15 @@ It depends on:
I made volsv so that I could use it with keybindings to control the volume, regardless of whether or not I was running pulseaudio, since I dislike pulseaudio and tend to avoid it when possible. This means I can have a consistent keybinding, whether or not I'm using it. Additionally, this would give me less keybindings to have to port to OpenBSD, which I occasionally install from time to time, although I haven't booted into it since I started writing this script. Additionally, it has provided a fun learning experience as I learn to write scripts.
+#### Flags/Commands
+
+- increase volume: `up` or `-i`
+- decrease volume: `down` or `-d`
+- toggle system mute: `toggle` or `-t`
+- toggle microphone mute\*: `mic` or `-m`
+- get volume level: `getv` or `-v`
+- get mute state: `getm` or `-g`
+
\*Volsv does not yet support muting the microphone in ALSA.
diff --git a/volsv b/volsv
index 16e3ce2..489e372 100755
--- a/volsv
+++ b/volsv
@@ -1,4 +1,8 @@
#!/bin/sh
+# calculate average of two integers (for ALSA)
+average () {
+ echo "$(( $(( $1 + $2 )) / 2 ))$"
+}
# print error message
printerror () {
echo "$1 is not a recognized command or flag"
@@ -10,7 +14,8 @@ pulsesv () {
"down" | "-d") pamixer -d 5 ;;
"toggle" | "-t") pamixer -t ;;
"mic" | "-m") pamixer --source 1 -t ;;
- "getm" | "-g") ;;
+ "getv" | "-v") printf "%s%%\n" "$(pamixer --get-volume)" ;;
+ "getm" | "-g") pamixer --get-mute | sed 's/[Ff]alse/\[on\]/;s/[Tt]rue/\[off\]/' ;;
*) printerror "$1" ;;
esac
}
@@ -20,7 +25,8 @@ alsasv () {
"up" | "-i") amixer sset Master 5%+ ;;
"down" | "-d") amixer sset Master 5%- ;;
"toggle" | "-t") amixer sset Master toggle ;;
- "getm" | "-g") ;;
+ "getv" | "-v") amixer sget Master | grep '\[[0-9]*\%\]' | cut -d' ' -f6 | sed 's/\[//;s/\]//g' ;;
+ "getm" | "-g") amixer sget Master | grep '\[o[fn]' | cut -d' ' -f8 | head -1 ;;
*) printerror "$1" ;;
esac
}