-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadjust
executable file
·62 lines (53 loc) · 1.69 KB
/
adjust
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
#!/usr/bin/sh
fail() {
echo "Invalid argument $1"
echo
echo "Usage: adjust [-h|--help] COMMAND ARGUMENT"
echo
echo "Available commands:"
echo " volume toggle Toggle mute"
echo " volume <+n%|-n%> <Raise|Lower> volume by n%"
echo " brightness <+n%|-n%> <Raise|Lower> brightness by n%"
exit 1
}
[ ! -z $1 ] && cmd=$1 || fail "$@ (See help text)"
[ ! -z $2 ] && arg=$2 || fail "$@ (See help text)"
# For example, split +10% -> [+,10%]
amount=0
[ $arg != "toggle" ] \
&& amount=`echo $arg | cut -c 2-` \
&& arg=`echo $arg | cut -c 1`
notify() {
notify-send.py $1 $2 \
--hint boolean:transient:true \
--replaces-process "${1}-popup"
#--hint string:image-path:video-display \
#int:has-percentage:`$2` \
}
get_brightness() {
echo "100 * `brightnessctl g` / `brightnessctl m`" | bc
}
adjust_brightness() {
case $1 in
"+") brightnessctl s +${2} && notify Brightness `get_brightness` ;;
"-") brightnessctl s ${2}- && notify Brightness `get_brightness` ;;
*) fail "$1 (expected + or -)" ;;
esac
}
adjust_volume() {
case $1 in
"toggle") \
pactl -- set-sink-mute 0 toggle \
&& notify "Mute" `pactl -- get-sink-mute 0 | awk '{ print $2 }'` ;;
"+" | "-") \
pactl -- set-sink-mute 0 0 \
&& pactl -- set-sink-volume 0 $1$2 \
&& notify Volume `pactl -- get-sink-volume 0 | awk '{ print $5 }'` ;;
*) fail "$1 (expected \"toggle\", \"+\" or \"-\")" ;;
esac
}
case $cmd in
"brightness") adjust_brightness $arg $amount ;;
"volume") adjust_volume $arg $amount ;;
*) fail "$1 (expected \"brightness\" or \"volume\")" ;;
esac