Fixed volume and message

This commit is contained in:
Tibo De Peuter 2022-06-02 11:44:45 +02:00
parent 0085b86afb
commit 4a323b1c21

View file

@ -2,6 +2,15 @@
# Show system status in notification, or your own message # Show system status in notification, or your own message
# Syntaxis: notify [-vb] [<title> <message>] # Syntaxis: notify [-vb] [<title> <message>]
# Requirements:
# - brightnessctl
# - pulsemixer
panic () {
>&2 echo "Syntaxis: notify [-vb] [<title> [<message>]]"
exit 1
}
# Get options # Get options
while getopts ":bv" options; do while getopts ":bv" options; do
case "${options}" in case "${options}" in
@ -9,18 +18,24 @@ while getopts ":bv" options; do
value=$( brightnessctl | grep -o "[0-9]*%" ) value=$( brightnessctl | grep -o "[0-9]*%" )
title="Brightness: ${value}" title="Brightness: ${value}"
timeout=2000 timeout=2000
class='top-center'
;; ;;
v) v)
value=$(pactl get-sink-volume @DEFAULT_SINK@ | cut -d '/' -f2 | grep -o '[0-9]*%') # Get volume
status=$(amixer get Master | grep "^ Front Left" | cut -d ' ' -f 8) value="$( pulsemixer --get-volume | cut -f1 -d' ' )%"
if [[ $status != "[on]" ]] ; then
value="Disabled" # If audio disabled
if [ ! "$( pulsemixer --get-mute )" -eq 0 ] ; then
width=0
value="${value} (Disabled)"
fi fi
title="Volume: ${value:-'0%'}" title="Volume: ${value:-'0%'}"
timeout=2000 timeout=2000
class='top-center'
;; ;;
*) *)
title="Unknown option" panic
;; ;;
esac esac
done done
@ -28,25 +43,24 @@ done
shift $((OPTIND - 1)) shift $((OPTIND - 1))
# Check arguments # Check arguments
if [[ $# -gt 2 ]] ; then if [ $# -gt 2 ] ; then
>&2 echo "Syntaxis: notify [-vb] [<title> [<message>]]" panic
exit 1 elif [ $# -eq 2 ] ; then
elif [[ $# -eq 2 ]] ; then
title=$1 title=$1
message=$2 message=$2
elif [[ $# -eq 1 ]] ; then elif [ $# -eq 1 ] ; then
title=$1 title=$1
fi fi
# Calculate length of coloured bar. # Calculate length of coloured bar.
if [[ "${value}" =~ ^[0-9]+%$ ]] ; then if [[ "${value}" =~ ^[0-9]+%$ && "${width:--1}" -ne 0 ]] ; then
width=$(grep -o "[0-9]*" <<< "${value}") width=$(grep -o "[0-9]*" <<< "${value}")
fi fi
# Send message # Send message
notify-send "${title}" "${message}" \ notify-send "${title}" "${message}" \
-t "${timeout:=5000}" \ -t "${timeout:=5000}" \
-c byMe \ -c "${class:=''}" \
-h int:value:"${width:=0}" \ -h int:value:"${width:=0}" \
-h string:x-canonical-private-synchronous:byMe # Replace if not yet gone -h string:x-canonical-private-synchronous:byMe # Replace if previous still exists