Call a popup with progress bar on changing brightness level

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
lxtr
Level 1
Level 1
Posts: 8
Joined: Sat Nov 20, 2021 12:34 pm

Call a popup with progress bar on changing brightness level

Post by lxtr »

Hi all!

I'm using simple script to change brightness to lower level

Code: Select all

#!/bin/bash

if ! [[ $(brightnessctl -d acpi_video0 get) = 1 ]]
then
    brightnessctl -d acpi_video0 set 1-
fi;
For changing brightness to higher level I run command

Code: Select all

brightnessctl -d acpi_video0 set +1
So, I want see a popup notify of current brightness value, like popup that shows during changing of volume level

Image

Can I acquire this by using some bash command?
Last edited by LockBot on Mon Feb 13, 2023 11:00 pm, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
1000
Level 6
Level 6
Posts: 1039
Joined: Wed Jul 29, 2020 2:14 am

Re: Call a popup with progress bar on changing brightness level

Post by 1000 »

Bash itself does not have a GUI.
You can use a simple notify-send notification. ( Mostly used in bash )
for example https://www.baeldung.com/linux/script-gui-notification
There is also mention about zenity
These are the simplest programs and they don't have window formatting options.

You can try create something more advanced and run in bash.
I don't know if this link is appropriate
https://wiki.archlinux.org/title/Desktop_notifications

In theory, the notification is usually a window which is sensitive to clicking with no frame or buttons.
So usually no additional library required - only lib for GUI

Edited.
You can also check the source code of the program as it is built. You can also see how plugins for your desktop environment are built.
But plugins are usually not portable between different desktop environments.
Maybe I seen an example in this forum for Cinnamon, you can try search.

Edited

Interesting links:
1. " Writing a simple task Applet for Cinnamon Desktop "
https://benjuan26.com/blog/writing-a-si ... n-desktop/
2. " GNOME applications in JavaScript "
viewtopic.php?p=1820801#p1820801
3. Desktop Notifications Specification
https://specifications.freedesktop.org/ ... ec/latest/
1000
Level 6
Level 6
Posts: 1039
Joined: Wed Jul 29, 2020 2:14 am

Re: Call a popup with progress bar on changing brightness level

Post by 1000 »

You can try play with this examples.
( Script a little unfinished, but I don't have time )

Code: Select all

#!/bin/bash


##      License: GNU GPL v.3		http://www.gnu.org/licenses/gpl-3.0.en.html
        VERSION='1'
##      Destiny: These are examples only with progress bar and with slider.
##      Script usage: bash script_name 
#===========================

case $1 in

	"--help"|"-h")
	
	    echo " " 
	    echo "Available Options:"

	    echo ' --higher  or  +     = To higher level of brightness.'
	    echo " " 
	    echo ' --lower   or  -     = To lower level of brightness.'
	    echo " " 
	    echo ' --help    or  -h    = To display this description and finish.'
	    echo " " 
	    
	;;
	"--higher"|"+")

        # brightnessctl -d acpi_video0 set +1
        # GET_CURRENT_VALUE=$(brightnessctl g)
        GET_CURRENT_VALUE=$(echo 70)
	    ( echo "$GET_CURRENT_VALUE" ; sleep 2 ) | zenity --progress --auto-close
	     
	;;
	"--lower"|"-")
	
	    # brightnessctl -d acpi_video0 set 1-
	    # GET_CURRENT_VALUE=$(brightnessctl g)
	    GET_CURRENT_VALUE=$(echo 40)
	    ( echo "$GET_CURRENT_VALUE" ; sleep 2 ) | zenity --progress --auto-close 

	;;
	"--zenity-slider"|"-zs")
	    
	    OLD_CURRENT_VALUE=$(echo 40)
	    zenity --scale --print-partial --value="$OLD_CURRENT_VALUE" |  while read ScaleNumber ; do
	        if [[ "$ScaleNumber" -lt "$OLD_CURRENT_VALUE" ]] ; then  
	            echo "set command with $ScaleNumber -"
	        elif [[ "$ScaleNumber" -gt "$OLD_CURRENT_VALUE" ]] ; then
	            echo "set command with $ScaleNumber +"
	        else 
	            echo "Error: ScaleNumber = $ScaleNumber"
	        fi 
	        
	        OLD_CURRENT_VALUE="$ScaleNumber"
	    done
	    
	  	;;
	"--progress-bar"|"-pb") 
	 
        echo -n "["
        for ((i = 0 ; i <= 100 ; i+=10)); do
            echo -ne "###\e[s] ($i%)\e[u"
            sleep 0.5
        done
        echo " "

	  	;;
	"--bash-slider"|"-bs") 
	
	    OLD_CURRENT_VALUE=$(echo 40)
	    
        echo -n "["
        while : ; do
            read -r -n1   KEY
            

            [[ "$KEY" == "q" ]] && exit 
            if [[ "$KEY" == "+" ]] ; then
            
                OLD_CURRENT_VALUE=$((${OLD_CURRENT_VALUE}+10))
                [[ "$OLD_CURRENT_VALUE" -gt "100" ]] && OLD_CURRENT_VALUE="100"
                VI=$(printf "%-*s" $((${OLD_CURRENT_VALUE}/2)) '[' | tr ' ' '#')

            elif [[ "$KEY" == "-" ]] ; then
            
                OLD_CURRENT_VALUE=$((${OLD_CURRENT_VALUE}-10))
                [[ "$OLD_CURRENT_VALUE" -lt "1" ]] && OLD_CURRENT_VALUE="0"
                
                echo -n "    "
                VI=$(printf "%-*s" $((${OLD_CURRENT_VALUE}/2)) '[' | tr ' ' '#')
            fi
            
            echo -ne "$VI % $OLD_CURRENT_VALUE \r"
            sleep 0.2
        done
        echo " "
	
	;;
	*)
		echo "Unknown option: $1"
		echo "	Try use: $0 --help"
	;; 
esac
	    
lxtr
Level 1
Level 1
Posts: 8
Joined: Sat Nov 20, 2021 12:34 pm

Re: Call a popup with progress bar on changing brightness level

Post by lxtr »

1000 wrote: Sun Aug 14, 2022 6:48 pm You can try play with this examples.
Thanks! I will try your code!
lxtr
Level 1
Level 1
Posts: 8
Joined: Sat Nov 20, 2021 12:34 pm

Re: Call a popup with progress bar on changing brightness level

Post by lxtr »

At last - my final result, if anyone need it

Code: Select all

#!/bin/bash

case $1 in

	"+")

        if [[ $(brightnessctl -d acpi_video0 get) -lt 100 ]]
        then
            brightnessctl -d acpi_video0 set +1
            CURRENT_BRIGHTNESS_VALUE=$(brightnessctl -d acpi_video0 get)

	        gdbus call --session --dest 'org.Cinnamon' --object-path '/org/Cinnamon' --method 'org.Cinnamon.ShowOSD' "{'icon': <'display-brightness-symbolic'>, 'level': <'${CURRENT_BRIGHTNESS_VALUE}'>}"
        fi;

	;;
	"-")
	
        if [[ $(brightnessctl -d acpi_video0 get) -gt 1 ]]
        then
            brightnessctl -d acpi_video0 set 1-
            CURRENT_BRIGHTNESS_VALUE=$(brightnessctl -d acpi_video0 get)

	        gdbus call --session --dest 'org.Cinnamon' --object-path '/org/Cinnamon' --method 'org.Cinnamon.ShowOSD' "{'icon': <'display-brightness-symbolic'>, 'level': <'${CURRENT_BRIGHTNESS_VALUE}'>}"
        fi;

	;;
esac
Locked

Return to “Scripts & Bash”