· 6 years ago · Aug 04, 2019, 08:36 PM
1amixer set Master mute
2amixer set Master unmute
3
4amixer set Master toggle
5
6pactl set-sink-mute 0 1
7
8pactl set-sink-mute 0 0
9
10DEFAULT_SINK=$(pactl info | grep "Default Sink" | cut -d " " -f3)
11
12pactl set-sink-mute "$DEFAULT_SINK" "1"
13
14pactl set-sink-mute "$DEFAULT_SINK" "0"
15
16#!/bin/bash
17# script name: volume
18# Author: glaudistong at gmail.com
19# depends on: yad, coreutils, pulseaudio
20
21ps -ef | grep "yad" | grep -E "Volume [^+-]" | tr -s " " | cut -d " " -f2 | xargs -i kill "{}" 2>/dev/null
22DEFAULT_SINK=$(pactl info | grep "Default Sink" | cut -d " " -f3)
23DEFAULT_SOURCE=$(pactl info | grep "Default Source" | cut -d " " -f3)
24case "$1" in
25 init)
26 {
27 ps -fe | grep yad | grep -q volume ||
28 {
29 yad --notification --command "volume up" --text "+ Volume +" --image ~/Pictures/volume-up-dark.png &
30 yad --notification --command "volume down" --text "- Volume -" --image ~/Pictures/volume-down-dark.png &
31 }
32 };;
33 up)
34 {
35 pactl set-sink-volume "$DEFAULT_SINK" +5%
36 P=$(pactl list | grep -E "Name: $DEFAULT_SINK$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
37 iconl="$(echo -ne "U1F50A")"
38 iconr="$(echo -ne "U1F56A")"
39 timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$iconl Volume $P% $iconr" --no-focus --center --skip-taskbar --on-top &
40 };;
41 down)
42 {
43 pactl set-sink-volume "$DEFAULT_SINK" -5%
44 P=$(pactl list | grep -E "Name: $DEFAULT_SINK$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
45 iconl="$(echo -ne "U1F509")"
46 iconr="$(echo -ne "U1F569")"
47 timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$iconl Volume $P% $iconr" --no-focus --center --skip-taskbar --on-top &
48 };;
49 mute)
50 {
51 ismute=$(pactl list | grep -E "Name: $DEFAULT_SINK$|Mute" | grep "Name:" -A1 | tail -1 |cut -d: -f2| tr -d " ")
52 if [ "$ismute" == no ]; then
53 s=1
54 P=0
55 icon="$(echo -ne "U1F507")"
56 else
57 P=$(pactl list | grep -E "Name: $DEFAULT_SINK$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
58 icon="?"
59 s=0
60 fi
61 pactl set-sink-mute "$DEFAULT_SINK" "$s"
62 echo $s > /sys/devices/platform/thinkpad_acpi/leds/platform::mute/brightness
63 timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$icon Volume $P%" --no-focus --center --skip-taskbar --on-top &
64 };;
65 mic-up)
66 {
67 pactl set-source-volume "$DEFAULT_SOURCE" +5%
68 P=$(pactl list | grep -E "Name: $DEFAULT_SOURCE$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
69 icon="$(echo -en "U1F3A4")"
70 timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$icon Volume Mic $P%" --no-focus --center --skip-taskbar --on-top &
71 };;
72 mic-down)
73 {
74 pactl set-source-volume "$DEFAULT_SOURCE" -5%
75 icon="$(echo -en "U1F3A4")"
76 P=$(pactl list | grep -E "Name: $DEFAULT_SOURCE$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
77 timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$icon Volume Mic $P%" --no-focus --center --skip-taskbar --on-top &
78 };;
79 mic-mute)
80 {
81 ismute=$(pactl list | grep -E "Name: $DEFAULT_SOURCE$|Mute" | grep "Name:" -A1 | tail -1 |cut -d: -f2| tr -d " ")
82 if [ "$ismute" == no ]; then
83 s=1
84 P=0
85 icon="$(echo -en "U1F507U1F3A4")"
86 else
87 P=$(pactl list | grep -E "Name: $DEFAULT_SOURCE$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
88 s=0
89 icon="$(echo -en "U1F3A4")"
90 fi
91 pactl set-source-mute "$DEFAULT_SOURCE" "$s"
92 echo $s > /sys/devices/platform/thinkpad_acpi/leds/platform::micmute/brightness
93 timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$icon Volume Mic $P%" --no-focus --center --skip-taskbar --on-top &
94 };;
95 *)
96 echo invalid option;;
97esac;