dunst-project / dunst

Lightweight and customizable notification daemon
https://dunst-project.org
Other
4.62k stars 342 forks source link

How to output a certain part of notification to right side? #743

Closed apoorv569 closed 2 years ago

apoorv569 commented 4 years ago

I'm using a script for showing me my volume and brightness level via Dunst which looks like this - Peek 2020-07-28 13-35

But this always shows the (volume)% in the beginning and as I raise it pushes forward to right side. Is there a way to permanently display the (volume)% to right side and the icon and progress bar to where they are.

Here is the script I'm using for volume -

#!/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
}

vol_get=$(amixer get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1)

function send_notification {
  iconSound="~/.local/bin/high-volume-w.png"
  iconMuted="~/.local/bin/mute.png"
  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   $vol_get %"
  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

I got this script from here -

https://www.reddit.com/r/unixporn/comments/9i5seg/brightness_and_volume_notifications_with_dunst_oc/ https://gist.github.com/Blaradox/030f06d165a82583ae817ee954438f2e

Also is there a way to make the icon that shows change when say volume from 0-25% shows icon-a, 25-50% shows icon-b, 50-75% shows icon-c and 75-100% icon-d.

tsipinakis commented 4 years ago

The only way would be to insert spaces to compensate, so for example level 1 is 1 bar and 9 spaces, level 2 2 bars and 8 spaces etc

apoorv569 commented 4 years ago

The only way would be to insert spaces to compensate, so for example level 1 is 1 bar and 9 spaces, level 2 2 bars and 8 spaces etc

Right now it is like this

dunstify -i $iconSound -r 2593 -u normal "    $bar   $vol_get %"

You mean I should add spaces like this

dunstify -i $iconSound -r 2593 -u normal "    $bar          $vol_get %"

Adding spaces like this pushes the (volume) % even further when raised, and as it reaches 100%, it wraps to next line.

Peek 2020-07-28 18-05

Narrat commented 4 years ago

Number of spaces depending on the size of your current $bar. So instead of hardcoded spaces in your dunstify command you need another variable which is kinda inverted to your $bar variable. Kinda like filler_spaces=<wherever your number should be> - $bar. This is kinda simplified what needs to be done. After looking at the scripts, you would need to deduce what the command for bar does and how you could inject your wanted spaces.

apoorv569 commented 4 years ago

Number of spaces depending on the size of your current $bar. So instead of hardcoded spaces in your dunstify command you need another variable which is kinda inverted to your $bar variable. Kinda like filler_spaces=<wherever your number should be> - $bar. This is kinda simplified what needs to be done. After looking at the scripts, you would need to deduce what the command for bar does and how you could inject your wanted spaces.

I'm not a expert at this, but did you mean I should

spaces=20 - $bar

and then

dunstify -i $iconSound -r 2593 -u normal "    $bar $spaces $vol_get %"
Narrat commented 4 years ago

Yes, like that. But instead of using $bar (which contains the line to print. Sorry for being unclear what I meant when I used $bar in my previous post) you should use $volume. Or more exactly the calculation for the steps: $((volume / 5)) So it should look like: ~spaces=$((20 - $((volume / 5)))~ (not exactly sure if I overdid it with the $(), because I'm not experienced with calculations in the shell). Will look this up and edit my comment

Edit: spaces=$(( 20 - (volume / 5) )) should be good. Cannot test it though, as for me the get_volume function in the script returns an invalid number. I would need to tinker with that first. But in general this calculation should do the trick.

apoorv569 commented 4 years ago

Yes, like that. But instead of using $bar (which contains the line to print. Sorry for being unclear what I meant when I used $bar in my previous post) you should use $volume. Or more exactly the calculation for the steps: $((volume / 5)) So it should look like: ~spaces=$((20 - $((volume / 5)))~ (not exactly sure if I overdid it with the $(), because I'm not experienced with calculations in the shell). Will look this up and edit my comment

Edit: spaces=$(( 20 - (volume / 5) )) should be good. Cannot test it though, as for me the get_volume function in the script returns an invalid number. I would need to tinker with that first. But in general this calculation should do the trick.

Adding this

spaces=$(( 20 - (volume / 5) ))

and

dunstify -i $iconSound -r 2593 -u normal "    $bar $spaces $vol_get %"

gives me this Peek 2020-07-30 02-18

and its also showing error in vim Peek 2020-07-30 02-21

Narrat commented 4 years ago

Gosh.. Today I'm kinda standing next to me -_- One important thing is of course missing: The spaces need to be drawn. Until now we only get a value (in the best case). So it is needed to incorporate the seq call like in bar One general note though: The new var will need to added to function send_notification. It needs to be recalculated with every change

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')
    spaces=$(seq --separator=" " 0 "$(( 20 - (volume / 5) ))" | sed 's/[0-9]//g')
    # Send the notification
    dunstify -i $iconSound -r 2593 -u normal "    ${bar}${spaces} $vol_get %"
  fi
}
apoorv569 commented 4 years ago

Gosh.. Today I'm kinda standing next to me -_- One important thing is of course missing: The spaces need to be drawn. Until now we only get a value (in the best case). So it is needed to incorporate the seq call like in bar One general note though: The new var will need to added to function send_notification. It needs to be recalculated with every change

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')
    spaces=$(seq --separator=" " 0 "$(( 20 - (volume / 5) ))" | sed 's/[0-9]//g')
    # Send the notification
    dunstify -i $iconSound -r 2593 -u normal "    ${bar}${spaces} $vol_get %"
  fi
}

OK, I added this in the function send_notification,

spaces=$(seq --separator=" " 0 "$(( 20 - (volume / 5) ))" | sed 's/[0-9]//g')

and

dunstify -i $iconSound -r 2593 -u normal "    ${bar}${spaces} $vol_get %"

its the same still, pushes the (volume) % and also starts at a weird position. Peek 2020-07-30 03-55

apoorv569 commented 4 years ago

Gosh.. Today I'm kinda standing next to me -_- One important thing is of course missing: The spaces need to be drawn. Until now we only get a value (in the best case). So it is needed to incorporate the seq call like in bar One general note though: The new var will need to added to function send_notification. It needs to be recalculated with every change

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')
    spaces=$(seq --separator=" " 0 "$(( 20 - (volume / 5) ))" | sed 's/[0-9]//g')
    # Send the notification
    dunstify -i $iconSound -r 2593 -u normal "    ${bar}${spaces} $vol_get %"
  fi
}

OK, I just edited and updated the script with Pulseaudio commands, Alsa commands are commented out.

!/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
 pactl list sinks | grep "Volume:" | awk 'NR==1 {print $5}' | sed 's/[^0-9]*//g'
}

function is_mute {
 # amixer get Master | grep '%' | grep -oE '[^ ]+$' | grep off > /dev/null
 pactl list sinks | grep "Mute:" | awk '{print $2}' | grep yes > /dev/null
}

#vol_get=$(amixer get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1)
vol_get=$(pactl list sinks | grep "Volume:" | awk 'NR==1 {print $5}' | sed 's/[^0-9]*//g')

function send_notification {
  iconSound="~/.local/bin/high-volume-w.png"
  iconMuted="~/.local/bin/mute-w.png"
  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 / 2))" | sed 's/[0-9]//g')
    spaces=$(seq --separator=" " 0 "$(( 50 - (volume / 2) ))" | sed 's/[0-9]//g')
    # Send the notification
    dunstify -i $iconSound -r 2593 -u normal "  ${bar}${spaces} $vol_get %"
  fi
}

case $1 in
  up)
    # set the volume on (if it was muted)
   # amixer -D pulse set Master on > /dev/null
    pactl set-sink-mute @DEFAULT_SINK@ false > /dev/null
    # up the volume (+ 5%)
   # amixer -D pulse sset Master 5%+ > /dev/null
    pactl set-sink-volume @DEFAULT_SINK@ +2%
    send_notification
    ;;
  down)
   # amixer -D pulse set Master on > /dev/null
    pactl set-sink-mute @DEFAULT_SINK@ false > /dev/null
   # amixer -D pulse sset Master 5%- > /dev/null
    pactl set-sink-volume @DEFAULT_SINK@ -2%
    send_notification
    ;;
  mute)
    # toggle mute
   # amixer -D pulse set Master 1+ toggle > /dev/null
   pactl set-sink-mute @DEFAULT_SINK@ toggle > /dev/null
    send_notification
    ;;
esac
Narrat commented 4 years ago

Does it work better with pactl? And regarding the weird behaviour: it kinda looks like it is working. What still can be an issue is the used font. And maybe the calculation needs to be adjusted

apoorv569 commented 4 years ago

Does it work better with pactl? And regarding the weird behaviour: it kinda looks like it is working. What still can be an issue is the used font. And maybe the calculation needs to be adjusted

No I just wanted to use pactl because I'm a pulse user, it works the same still. I'll try to adjust the font and calculations and see if it gets better.

apoorv569 commented 4 years ago

Does it work better with pactl? And regarding the weird behaviour: it kinda looks like it is working. What still can be an issue is the used font. And maybe the calculation needs to be adjusted

Well I reduced the font by 1 point, it now start at weird position and when I raise 1 point volume i.e +2%, it pushes to the right and after every increment it still pushes it forward. Peek 2020-07-30 16-31

Also I noticed it reports the volume 1 point i.e 2% less, meaning if the actual volume is 20, in the notification is says 2% less i.e 18.

Narrat commented 4 years ago

The note regarding the font was more a question about what font do you use? Still a monospace font? From the videos it looks like the big dash takes more space than the space, therefor this pushing behaviour the more dashes are displayed. To confirm this you could change the symbol of the spaces bar to the same as bar

apoorv569 commented 4 years ago

The note regarding the font was more a question about what font do you use? Still a monospace font? From the videos it looks like the big dash takes more space than the space, therefor this pushing behaviour the more dashes are displayed. To confirm this you could change the symbol of the spaces bar to the same as bar

I'm using Noto Sans Regular 8 and by changing spaces to the same symbol as bar

     bar=$(seq --separator="─" 0 "$((volume / 2))" | sed 's/[0-9]//g')
     spaces=$(seq --separator="─" 0 "$(( 50 - (volume / 2) ))" | sed 's/[0-9]//g')
     # Send the notification
     dunstify -i $iconSound -r 2593 -u normal "  ${bar}${spaces} $vol_get %"

it looks like this Peek 2020-07-30 22-36

Narrat commented 4 years ago

Changing it to Noto Sans Mono Regular should help with this. To be working like that, the bar needs a monospace font. Or the value needs to stay in front of the bar. Or move to a new line. But it will change for all notifications (dunno if it is possible to set a font just for one specific event) Otherwise there is the corner case with 100%, where it grows in size. And if you want to use +100% you would need to incorporate this in the script/calculation. Dunno about the off by 2% values

apoorv569 commented 4 years ago

Changing it to Noto Sans Mono Regular should help with this. To be working like that, the bar needs a monospace font. Or the value needs to stay in front of the bar. Or move to a new line. But it will change for all notifications (dunno if it is possible to set a font just for one specific event) Otherwise there is the corner case with 100%, where it grows in size. And if you want to use +100% you would need to incorporate this in the script/calculation. Dunno about the off by 2% values

OK, I changed the font to Noto Sans Mono Regular its still like this Peek 2020-07-30 23-08

Now why is it starting from line below, I did not change anything

function send_notification {
  iconSound="~/.local/bin/high-volume-w.png"
  iconMuted="~/.local/bin/mute-w.png"
  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 / 2))" | sed 's/[0-9]//g')
    spaces=$(seq --separator=" " 0 "$(( 50 - (volume / 2) ))" | sed 's/[0-9]//g')
    # Send the notification
    dunstify -i $iconSound -r 2593 -u normal "  ${bar}${spaces} $vol_get %"

:disappointed:

Narrat commented 4 years ago

Well, there are the corner cases 0% and 100% and you set the max length of the bar to 50 chars, which takes a lot of space. For debugging purposes you could print the value of volume in the dunstify command and set " " to "+" or the like so you can distinguish between what is printed by bar and what by spaces. Or even calculate the end values of the seq calls in separate vars which you also could print. Helps to see if the numbers matches the expectation. And maybe that makes easier to understand the problem and find a solution.

apoorv569 commented 4 years ago

Well, there are the corner cases 0% and 100% and you set the max length of the bar to 50 chars, which takes a lot of space. For debugging purposes you could print the value of volume in the dunstify command and set " " to "+" or the like so you can distinguish between what is printed by bar and what by spaces. Or even calculate the end values of the seq calls in separate vars which you also could print. Helps to see if the numbers matches the expectation. And maybe that makes easier to understand the problem and find a solution.

OK, by changing the spaces symbol to + I finally understood whats going on, I tried the value from 50 to something else and 30 seems to work the best, also changed the value its being divided by to 5 instead of 2, it looks fine now

    bar=$(seq --separator="─" 0 "$((volume / 5))" | sed 's/[0-9]//g')
    spaces=$(seq --separator="+" 0 "$(( 30 - (volume / 5) ))" | sed 's/[0-9]//g')
    # Send the notification
    dunstify -i $iconSound -r 2593 -u normal "  ${bar}${spaces} $vol_get %"

it looks like this now Peek 2020-07-30 23-51 It still pushes forward after 150% or something but I don't need anymore than that, finally its good enough for now. Can you tell me how to stop it from going over 150%.

apoorv569 commented 4 years ago

Well, there are the corner cases 0% and 100% and you set the max length of the bar to 50 chars, which takes a lot of space. For debugging purposes you could print the value of volume in the dunstify command and set " " to "+" or the like so you can distinguish between what is printed by bar and what by spaces. Or even calculate the end values of the seq calls in separate vars which you also could print. Helps to see if the numbers matches the expectation. And maybe that makes easier to understand the problem and find a solution.

OK, I did this same for my brightness script and tested on my laptop,

function get_brightness {
xbacklight -get | cut -d '.' -f 1
}

 c_bright=$(xbacklight -get | cut -d '.' -f 1)

function send_notification {
  icon="~/.local/bin/brightness-w.png"
  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')
  spaces=$(seq -s "+" 0 $(( 30 - (brightness / 5) )) | sed 's/[0-9]//g')
  # Send the notification
  dunstify -i "$icon" -r 5555 -u normal "  ${bar}${spaces} $c_bright %"
}

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

Peek 2020-07-31 00-28

I had to divide it by 3 instead of 5 and change the length to 33 instead of 30, to get proper output, otherwise it stops before reaching the end, and spaces are still visible i.e +

  bar=$(seq -s "─" 0 $((brightness / 3)) | sed 's/[0-9]//g')
  spaces=$(seq -s "+" 0 $(( 33 - (brightness / 3) )) | sed 's/[0-9]//g')

also had to delete the spaces in dunstify before $bar otherwise the % symbol gets pushed to next line.

dunstify -i "$icon" -r 5555 -u normal "${bar}${spaces} $c_bright %"

it now looks like this Peek 2020-07-31 00-37

Is there someway to have space before $bar in the dunstify command, because without spaces the progress bar seems too close to the icon.

Narrat commented 4 years ago

Great if it is finally working like you wanted to (or mostly :D) Regarding your last question: Either it is possible to tell PA a max volume of 150% or you would need to set a upper threshold. Which involves an if-clause. The calculation of the end values would need be set in temp variables and said if-clause is used to check if they exceed a certain value. If they do, then it sets the var to value X and if not it calculates the normal way. The same applies for your initial question regarding if it possible to get different icons. Yes it is possible. Either via an if-clause (depending on the volume level it chooses the icon you set for it) or switch-case. Both means the script needs to be extended with some additional logic.

apoorv569 commented 4 years ago

Great if it is finally working like you wanted to (or mostly :D) Regarding your last question: Either it is possible to tell PA a max volume of 150% or you would need to set a upper threshold. Which involves an if-clause. The calculation of the end values would need be set in temp variables and said if-clause is used to check if they exceed a certain value. If they do, then it sets the var to value X and if not it calculates the normal way. The same applies for your initial question regarding if it possible to get different icons. Yes it is possible. Either via an if-clause (depending on the volume level it chooses the icon you set for it) or switch-case. Both means the script needs to be extended with some additional logic.

I have this other script that I was using for DWM statusbar to control volume,

#!/bin/sh

# Prints the current volume or 🔇 if muted. Uses PulseAudio by default,
# uncomment the ALSA lines if you remove PulseAudio.

case $BLOCK_BUTTON in
    1) setsid -f pavucontrol ;;
    2) pactl set-sink-mute @DEFAULT_SINK@ toggle ;;
    4) pactl set-sink-volume @DEFAULT_SINK@ +2% ;;
    5) pactl set-sink-volume @DEFAULT_SINK@ -2% ;;
    3) notify-send "📢 Volume module" "\- Shows volume 🔊, 🔇 if muted.
- Middle click to mute.
- Scroll to change." ;;
    6) "st" -e "$EDITOR" "$0" ;;
esac

volstat="$(pactl list sinks)"
# volstat="$(amixer get Master)" # ALSA only equivalent.

#echo "$volstat" | grep -q "Mute: yes" && printf " ﱝ \\n" && exit
# echo "$volstat" | grep "\[off\]" >/dev/null && printf "🔇\\n" && exit # ALSA

vol="$(echo "$volstat" | grep '[0-9]\+%' | awk NR==3 | sed "s,.* \([0-9]\+\)%.*,\1,;1q")"
# vol=$(echo "$volstat" | grep -o "\[[0-9]\+%\]" | sed "s/[^0-9]*//g;1q") # ALSA

if [ "$vol" -gt "70" ]; then
    icon=" "
elif [ "$vol" -lt "30" ]; then
    icon="奔"
else
    icon="墳"
fi

printf "%s%s%%\n" "$icon $vol"

You mean something like this can be used to different icons?

Narrat commented 4 years ago

Yes, something like this can be used. In special the part which changes the icon variable.

apoorv569 commented 4 years ago

Yes, something like this can be used. In special the part which changes the icon variable.

OK, I made a case statement for icon in the script

vol_get=$(pactl list sinks | grep "Volume:" | awk 'NR==1 {print $5}' | sed 's/[^0-9]*//g')

case $vol_get in
    1) if [ "$vol_get" -lt "25" ]; then
        icon="~/.local/bin/vol-off.png" 
       fi
    ;;
    2) if [ "$vol" -gt "25" ]; then
        icon="~/.local/bin/vol-low.png" 
       fi
    ;;
    3) if [ "$vol" -gt "50" ]; then
        icon="~/.local/bin/vol-med.png" 
       fi
    ;;
    4) if [ "$vol" -gt "75" ]; then
        icon="~/.local/bin/vol-high.png" 
       fi
    ;;
esac

and using the same dunstify command

dunstify -i $icon -r 2593 -u normal "  ${bar}${spaces} $vol_get %"

but its not showing any icon, instead its some random number 2593. Am I even on the right track?

Narrat commented 4 years ago

Interesting contruct, but a bit overkill and won't work that way ;) It should only be one of those. Either if or either case. Where if is easier to implement

vol_get=$(pactl list sinks | grep "Volume:" | awk 'NR==1 {print $5}' | sed 's/[^0-9]*//g')

if [ "$vol_get" -lt "25" ]; then
    icon="~/.local/bin/vol-off.png"
elif [ "$vol_get" -lt "50" ] && [ "$vol_get" -gt "25" ]; then
    icon="~/.local/bin/vol-low.png"
elif [ "$vol_get" -lt "75" ] && [ "$vol_get" -gt "50" ]; then
    icon="~/.local/bin/vol-med.png"
else
    icon="~/.local/bin/vol-high.png"
fi

Something like that

apoorv569 commented 4 years ago

Interesting contruct, but a bit overkill and won't work that way ;) It should only be one of those. Either if or either case. Where if is easier to implement

vol_get=$(pactl list sinks | grep "Volume:" | awk 'NR==1 {print $5}' | sed 's/[^0-9]*//g')

if [ "$vol_get" -lt "25" ]; then
  icon="~/.local/bin/vol-off.png"
elif [ "$vol_get" -lt "50" ] && [ "$vol_get" -gt "25" ]; then
  icon="~/.local/bin/vol-low.png"
elif [ "$vol_get" -lt "75" ] && [ "$vol_get" -gt "50" ]; then
  icon="~/.local/bin/vol-med.png"
else
  icon="~/.local/bin/vol-high.png"
fi

Something like that

OK, I did what you posted above, its working, but it sometimes shows the wrong icon, like when it reaches around 50 its shows the icon for above 75 then when I raise 1 more to 52 it changes to what it should be Peek 2020-07-31 03-15 It also does not report the correct volume, the $vol_get when ran in a terminal gives correct output, but in the notification its current volume - 2. See video here for better explanation - https://lbry.tv/@apoorv569:5/simplescreenrecorder-2020-07-31:1

Same thing happens with the brightness script, it shows 5 less than the actual value, as it increments in 5.

Narrat commented 4 years ago

In other languages you have <, <=, > and >= and such for comparing values. Working like the ones from math. In shell the gt means greater than x, lt means lower than x. For example [ "$vol_get" -lt "50" ] && [ "$vol_get" -gt "25" ] means it is valid for 26-49. And the next step doesn't cover 50 either. You will need to adjust the steps so everything is covered ;)

apoorv569 commented 4 years ago

In other languages you have <, <=, > and >= and such for comparing values. Working like the ones from math. In shell the gt means greater than x, lt means lower than x. For example [ "$vol_get" -lt "50" ] && [ "$vol_get" -gt "25" ] means it is valid for 26-49. And the next step doesn't cover 50 either. You will need to adjust the steps so everything is covered ;)

I made some adjustments, also added the icon for mute in the first if statement

vol_get=$(pactl list sinks | grep "Volume:" | awk 'NR==1 {print $5}' | sed 's/[^0-9]*//g')

if [[ "$(pactl list sinks | grep "Mute:" | awk '{print $2}' | grep yes > /dev/null)" != "" ]]; then
     icon="~/.local/bin/vol-mute.png" 
elif [ "$vol_get" -lt "26" ]; then
    icon="~/.local/bin/vol-off.png"
elif [ "$vol_get" -lt "51" ] && [ "$vol_get" -gt "24" ]; then
    icon="~/.local/bin/vol-low.png"
elif [ "$vol_get" -lt "76" ] && [ "$vol_get" -gt "49" ]; then
    icon="~/.local/bin/vol-med.png"
else
    icon="~/.local/bin/vol-high.png"
fi

icon for mute is not showing. And because of the it outputting the wrong value, as I showed in the video, if you watched that, its miscalculating the icon, for example when the notification is showing 24 its actually 26, but if press volume + button 1 time it goes 26 when its actually 28, and if I press volume - button then it shows 28. Its weird. Peek 2020-07-31 05-30 Hope this explains.

Narrat commented 4 years ago

Should work with the mute icon if you reduce the line between the test (written as [[ ]]) to "$(pactl list sinks | grep "Mute:" | grep yes) And regarding the wrong value. Well, you need to compare and look at the values which come from the pactl list sinks command. And compare it with pavucontrol. There isn't a way for the notification script to tamper with this information. And send_notification is called after changing the volume, so this can't be the issue either (displaying before changing).

apoorv569 commented 4 years ago

Should work with the mute icon if you reduce the line between the test (written as [[ ]]) to "$(pactl list sinks | grep "Mute:" | grep yes) And regarding the wrong value. Well, you need to compare and look at the values which come from the pactl list sinks command. And compare it with pavucontrol. There isn't a way for the notification script to tamper with this information. And send_notification is called after changing the volume, so this can't be the issue either (displaying before changing).

if "$(pactl list sinks | grep "Mute:" | awk '{print $2}' | grep yes)" != "" ; then
     icon="~/.local/bin/vol-mute.png" 

Doing this breaks the script, nothing shows can't adjust the volume even.

And regarding the wrong value this is the same command I'm using in script. Peek 2020-08-02 19-29

Narrat commented 4 years ago

No, you should change what was inside of the brackets. The square-brackets need to stay if [[ <changed line> ]]; then

Edit: if [[ "$(pactl list sinks | grep "Mute:" | grep yes) ]]; then

apoorv569 commented 4 years ago

No, you should change what was inside of the brackets. The square-brackets need to stay if [[ <changed line> ]]; then

Edit: if [[ "$(pactl list sinks | grep "Mute:" | grep yes) ]]; then

You said

Should work with the mute icon if you reduce the line between the test (written as [[ ]]) to "$(pactl list sinks | grep "Mute:" | grep yes) So I though need to remove square braces.

Anyway, the script works, but when I press mute it says Peek 2020-08-02 19-59

And un-muting shows the icon, so its working but its reversed, and only show icon for one way. Peek 2020-08-02 19-60

It should show mute icon when I mute, and when I un-mute it should change back to the current volume icon.

fwsmit commented 2 years ago

Closing this issue, since the need for this is less since the introduction of progress bars. If a different progress bar layout is desired, please open a new issue about that