slitaz-configs view rootfs/usr/bin/tazvolume @ rev 275

tazvolume: move id-file from /var/run to /tmp
(by default user have no write permissions in /var/run)
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Mar 11 16:13:17 2016 +0200 (2016-03-11)
parents 705e1ce7f30f
children
line source
1 #!/bin/sh
2 # Change sound volume with notifications
3 # SliTaz GNU/Linux
4 # Aleksej Bobylev <al.bobylev@gmail.com>, March, 2016
6 # Deal with commands: "toggle" (for mute/unmute), "+" and "-" (+- 5%), or number (set volume %)
7 case $1 in
8 toggle) amixer set Master toggle;;
9 "+") amixer set Master 5%+;;
10 "-") amixer set Master 5%-;;
11 *) amixer set Master "$1%";;
12 esac >/dev/null
15 [ -z $(which notify-send) ] && exit
16 # Deal with Freedesktop notification system
18 # Get current volume (0..100)
19 vol=$(amixer sget Master | tail -n1 | sed -n 's|.*\[\([0-9]*\)%.*|\1|p')
20 [ -z "$vol" ] && vol='0'
22 # Get notification ID to replace
23 nid='/tmp/notify.id'
24 if [ -f "$nid" ]; then
25 old=$(($(date -u +%s) - $(date -ur "$nid" +%s)))
26 # remove if older than 3 seconds
27 [ $old -gt 3 ] && rm "$nid"
28 fi
29 replace=''
30 [ -f "$nid" ] && replace="--replace-id=$(cat "$nid")"
32 # Define notification icon
33 muted=''
34 if [ $vol -eq 0 ] || amixer sget Master | tail -n1 | fgrep -q '[off]'; then
35 icon='audio-volume-muted'; muted="(muted)"
36 elif [ $vol -le 50 ]; then
37 icon='audio-volume-low';
38 elif [ $vol -le 75 ]; then
39 icon='audio-volume-medium';
40 else
41 icon='audio-volume-high';
42 fi
44 # Use hints to show gauge in Canonical's notify-osd
45 # Use text for other notify implementations
46 notify-send \
47 --hint=string:x-canonical-private-synchronous:yes \
48 --hint=int:value:$vol \
49 --icon=$icon \
50 --urgency=low \
51 --expire-time=2000 \
52 $replace \
53 --print-id \
54 "Volume" "$vol% $muted" \
55 > "$nid"