Created
May 11, 2020 16:45
-
-
Save xyzshantaram/acada73da940a473017a396ff728bbf3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
## Put it into /usr/bin as "sound" so you can type snazzy commands like "sound up" and "sound down" | |
get_active_sink() { | |
local is_running=$(pactl list sinks | grep RUNNING); # empty if nothing is playing | |
if [ -z $is_running ]; then # nothing is playing; get the highest-number sink (the one which was plugged in last, which you're most likely to be using.) | |
local index_line_no=$(pactl list sinks | tac | awk '/State: SUSPENDED/{print NR + 1};') | |
IFS=' ' read -ra line_no_arr <<< "$index_line_no" | |
local line_number=${line_no_arr[0]} | |
local index_line=$(pactl list sinks | tac | sed -n "$line_number"p); | |
else # something is playing, get that sink number | |
local line_number=$(pactl list sinks | awk '/State: RUNNING/{print NR - 1}') | |
local index_line=$(pactl list sinks | sed -n "$line_number"p); | |
fi | |
IFS=' ' read -ra arr <<< "$index_line" | |
echo ${arr[1]} | sed 's/#//g' | |
} | |
get_vol_string() { | |
local volume='vol at: '$(pamixer --sink $(get_active_sink) --get-volume)'%' | |
if [ $(pamixer --sink $(get_active_sink) --get-mute) == 'true' ]; then | |
echo '[muted]'$volume | |
else | |
echo $volume | |
fi | |
} | |
if [ -z $1 ]; then | |
get_vol_string; | |
elif [ $1 == 'up' ]; then | |
echo 'volup'; | |
pamixer --sink $(get_active_sink) -i 5 --allow-boost | |
elif [ $1 == 'down' ]; then | |
echo 'voldown'; | |
pamixer --sink $(get_active_sink) -d 5 | |
elif [ $1 == 'mute' ]; then | |
echo 'mute toggled' ; | |
pamixer --sink $(get_active_sink) --toggle-mute | |
elif [ $1 == 'muteon' ]; then | |
echo 'muting' ; | |
pamixer --sink $(get_active_sink) -m | |
elif [ $1 == 'muteoff' ]; then | |
echo 'unmuting' ; | |
pamixer --sink $(get_active_sink) -u | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment