-
-
Save iNoSec2/95950eac7f4a7da29d8390953b57a71d to your computer and use it in GitHub Desktop.
Notifications for brightness and volume, using dunstify
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
#!/usr/bin/env bash | |
# You can call this script like this: | |
# $ ./brightnessControl.sh up | |
# $ ./brightnessControl.sh down | |
# Script inspired by these wonderful people: | |
# https://github.com/dastorm/volume-notification-dunst/blob/master/volume.sh | |
# https://gist.github.com/sebastiencs/5d7227f388d93374cebdf72e783fbd6a | |
function get_brightness { | |
xbacklight -get | cut -d '.' -f 1 | |
} | |
function send_notification { | |
icon="preferences-system-brightness-lock" | |
brightness=$(get_brightness) | |
# Make the bar with the special character ─ (it's not dash -) | |
# https://en.wikipedia.org/wiki/Box-drawing_character | |
bar=$(seq -s "─" 0 $((brightness / 5)) | sed 's/[0-9]//g') | |
# Send the notification | |
dunstify -i "$icon" -r 5555 -u normal " $bar" | |
} | |
case $1 in | |
up) | |
# increase the backlight by 5% | |
xbacklight -inc 5 | |
send_notification | |
;; | |
down) | |
# decrease the backlight by 5% | |
xbacklight -dec 5 | |
send_notification | |
;; | |
esac |
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
#!/usr/bin/env bash | |
# You can call this script like this: | |
# $ ./volumeControl.sh up | |
# $ ./volumeControl.sh down | |
# $ ./volumeControl.sh mute | |
# Script modified from these wonderful people: | |
# https://github.com/dastorm/volume-notification-dunst/blob/master/volume.sh | |
# https://gist.github.com/sebastiencs/5d7227f388d93374cebdf72e783fbd6a | |
function get_volume { | |
amixer get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1 | |
} | |
function is_mute { | |
amixer get Master | grep '%' | grep -oE '[^ ]+$' | grep off > /dev/null | |
} | |
function send_notification { | |
iconSound="audio-volume-high" | |
iconMuted="audio-volume-muted" | |
if is_mute ; then | |
dunstify -i $iconMuted -r 2593 -u normal "mute" | |
else | |
volume=$(get_volume) | |
# Make the bar with the special character ─ (it's not dash -) | |
# https://en.wikipedia.org/wiki/Box-drawing_character | |
bar=$(seq --separator="─" 0 "$((volume / 5))" | sed 's/[0-9]//g') | |
# Send the notification | |
dunstify -i $iconSound -r 2593 -u normal " $bar" | |
fi | |
} | |
case $1 in | |
up) | |
# set the volume on (if it was muted) | |
amixer -D pulse set Master on > /dev/null | |
# up the volume (+ 5%) | |
amixer -D pulse sset Master 5%+ > /dev/null | |
send_notification | |
;; | |
down) | |
amixer -D pulse set Master on > /dev/null | |
amixer -D pulse sset Master 5%- > /dev/null | |
send_notification | |
;; | |
mute) | |
# toggle mute | |
amixer -D pulse set Master 1+ toggle > /dev/null | |
send_notification | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment