-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp-volume.sh
executable file
·63 lines (54 loc) · 1.71 KB
/
app-volume.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
## script description
# this script allows to
# - list the application sinks
# - set the volume for an application sink by application name
# based on https://askubuntu.com/a/1418749
## global variables
SCRIPT=`basename $0`
DEBUG=false
(${DEBUG}) && echo "debug mode active"
(${DEBUG}) && set -x
#warning, this will terminate the script on errors
#do not use this if errors are expected behavior!
set -e
## display usage on invalid amount of arguments or help arguments
function usage() {
echo "usage: $SCRIPT {list|set <app> <volume>}"
echo "arguments"
echo " argument argument description"
echo " list list app sinks"
echo " set <app> <volume> set volume for <app> to <volume>%"
exit 1
}
function set-app-volume() {
player="$1"
volume="$2"
# get specific app sink
firstPlayerSinkIndex="$(pacmd list-sink-inputs | awk '/index:|application.name |application.process.binary / {print $0}' | sed 's/^ *//g ; s/.*= //' | grep -iB 1 "${player}" | awk '/index:/ {print $2; exit}')"
# I don't see the need to do this calculation here if pactl takes percentages direct anyway...
# 100% → 65536
#[[ $firstPlayerSinkIndex ]] && pacmd set-sink-input-volume "$firstPlayerSinkIndex" "$((volume*65536/100))"
[[ $firstPlayerSinkIndex ]] && pactl set-sink-input-volume "$firstPlayerSinkIndex" "${volume}%"
}
function list-app-sinks() {
pacmd list-sink-inputs | awk '/index:|volume: |application.name |application.process.binary / {print $0}' | sed 's/^[ \t]*//g'
}
case "$1" in
list)
list-app-sinks
;;
set)
#if arguments < 3 show usage
if [ $# -ne 3 ]
then
usage
fi
set-app-volume $2 $3
;;
*)
usage
;;
esac
(${DEBUG}) && set +x
exit 0