Compare commits

...

4 commits

Author SHA1 Message Date
c56fc16b7d src/brightness: add 2025-08-14 20:34:21 +00:00
b5796746f2 src/battery: add 2025-08-14 20:34:04 +00:00
479ed6be92 src/audio: update
Update icon path, remove minor error and change steps to 5%.
2025-08-14 20:33:09 +00:00
944201b3bb README.md: update 2025-08-14 20:09:43 +00:00
4 changed files with 113 additions and 33 deletions

View file

@ -1,2 +1,3 @@
# notifiers
A set of scripts that use [libnotify](https://gitlab.gnome.org/GNOME/libnotify) to notify about various states of a Linux system.

View file

@ -5,7 +5,7 @@ function notify_state {
case "$type" in
"sink") # Handle notifications for audio sink (output)
# Read the last audio sink notification ID from state, or set default if it does not exist
sink_last_notify_id="$(cat $HOME/.local/state/audio/sink || echo "1024")"
sink_last_notify_id="$(cat "$HOME/.local/state/audio/sink" || echo "1024")"
# Get the volume level and mute status of the default audio sink
local volume="$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '{print $2 * 100}')"
@ -16,22 +16,22 @@ function notify_state {
# Send a different notification based on the volume level
if [ $volume -gt 67 ]; then
sink_last_notify_id="$(notify-send "Volume sink: ${volume}%" -h int:value:${volume} -h string:synchronous: -i $sink_high -t 2000 -r $sink_last_notify_id -p)"
sink_last_notify_id="$(notify-send "Volume sink: ${volume}%" -h int:value:$volume -h string:synchronous: -i $sink_high -t 2000 -r $sink_last_notify_id -p)"
elif [ $volume -gt 33 ]; then
sink_last_notify_id="$(notify-send "Volume sink: ${volume}%" -h int:value:${volume} -h string:synchronous: -i $sink_medium -t 2000 -r $sink_last_notify_id -p)"
sink_last_notify_id="$(notify-send "Volume sink: ${volume}%" -h int:value:$volume -h string:synchronous: -i $sink_medium -t 2000 -r $sink_last_notify_id -p)"
else
sink_last_notify_id="$(notify-send "Volume sink: ${volume}%" -h int:value:${volume} -h string:synchronous: -i $sink_low -t 2000 -r $sink_last_notify_id -p)"
sink_last_notify_id="$(notify-send "Volume sink: ${volume}%" -h int:value:$volume -h string:synchronous: -i $sink_low -t 2000 -r $sink_last_notify_id -p)"
fi
else
sink_last_notify_id="$(notify-send "Volume sink: muted" -h int:value:${volume} -h string:synchronous: -i $sink_muted -t 2000 -r $sink_last_notify_id -p)"
sink_last_notify_id="$(notify-send "Volume sink: muted" -h int:value:$volume -h string:synchronous: -i $sink_muted -t 2000 -r $sink_last_notify_id -p)"
fi
# Write the last audio sink notification ID to state
echo $sink_last_notify_id > $HOME/.local/state/audio/sink
echo "$sink_last_notify_id" > "$HOME/.local/state/audio/sink"
;;
"source") # Handle notifications for audio source (input)
# Read the last audio source notification from state, or set default if it does not exist
source_last_notify_id="$(cat $HOME/.local/state/audio/source || echo "1024")"
# Read the last audio source notification ID from state, or set default if it does not exist
source_last_notify_id="$(cat "$HOME/.local/state/audio/source" || echo "1024")"
# Get the volume level and mute status of the default audio source
local volume="$(wpctl get-volume @DEFAULT_AUDIO_SOURCE@ | awk '{print $2 * 100}')"
@ -42,18 +42,18 @@ function notify_state {
# Send a different notification based on the volume level
if [ $volume -gt 67 ]; then
source_last_notify_id="$(notify-send "Volume source: ${volume}%" -h int:value:${volume} -h string:synchronous: -i $source_high -t 2000 -r $source_last_notify_id -p)"
source_last_notify_id="$(notify-send "Volume source: ${volume}%" -h int:value:$volume -h string:synchronous: -i $source_high -t 2000 -r $source_last_notify_id -p)"
elif [ $volume -gt 33 ]; then
source_last_notify_id="$(notify-send "Volume source: ${volume}%" -h int:value:${volume} -h string:synchronous: -i $source_medium -t 2000 -r $source_last_notify_id -p)"
source_last_notify_id="$(notify-send "Volume source: ${volume}%" -h int:value:$volume -h string:synchronous: -i $source_medium -t 2000 -r $source_last_notify_id -p)"
else
source_last_notify_id="$(notify-send "Volume source: ${volume}%" -h int:value:${volume} -h string:synchronous: -i $source_low -t 2000 -r $source_last_notify_id -p)"
source_last_notify_id="$(notify-send "Volume source: ${volume}%" -h int:value:$volume -h string:synchronous: -i $source_low -t 2000 -r $source_last_notify_id -p)"
fi
else
source_last_notify_id="$(notify-send "Volume source: muted" -h int:value:${volume} -h string:synchronous: -i $source_muted -t 2000 -r $source_last_notify_id -p)"
source_last_notify_id="$(notify-send "Volume source: muted" -h int:value:$volume -h string:synchronous: -i $source_muted -t 2000 -r $source_last_notify_id -p)"
fi
# Write the last audio source notification ID to state
echo $source_last_notify_id > $HOME/.local/state/audio/source
echo "$source_last_notify_id" > "$HOME/.local/state/audio/source"
;;
esac
}
@ -62,30 +62,31 @@ function notify_state {
type="$1"
action="$2"
# Define icon theme
icon_theme="tela-circle-black"
# Define icon theme and path
icon_theme="Tela-circle-black-dark"
icon_path="/usr/share/icons/${icon_theme}/24/panel"
# Define paths to icon files for different audio sink states
sink_high="/usr/share/icons/${icon_theme}/24/panel/audio-volume-high.svg"
sink_medium="/usr/share/icons/${icon_theme}/24/panel/audio-volume-medium.svg"
sink_low="/usr/share/icons/${icon_theme}/24/panel/audio-volume-low.svg"
sink_muted="/usr/share/icons/${icon_theme}/24/panel/audio-volume-muted.svg"
# Define icon files for different audio sink states
sink_high="${icon_path}/audio-volume-high.svg"
sink_medium="${icon_path}/audio-volume-medium.svg"
sink_low="${icon_path}/audio-volume-low.svg"
sink_muted="${icon_path}/audio-volume-muted.svg"
# Define paths to icon files for different audio source states
source_high="/usr/share/icons/${icon_theme}/24/panel/mic-volume-high.svg"
source_medium="/usr/share/icons/${icon_theme}/24/panel/mic-volume-medium.svg"
source_low="/usr/share/icons/${icon_theme}/24/panel/mic-volume-low.svg"
source_muted="/usr/share/icons/${icon_theme}/24/panel/mic-volume-muted.svg"
# Define icon files for different audio source states
source_high="${icon_path}/mic-volume-high.svg"
source_medium="${icon_path}/mic-volume-medium.svg"
source_low="${icon_path}/mic-volume-low.svg"
source_muted="${icon_path}/mic-volume-muted.svg"
# Determine action to take based on type
case "$type" in
"sink") # Actions for audio sink
case "$action" in
"volup") # Increase audio sink volume by 10%
wpctl set-volume @DEFAULT_AUDIO_SINK@ 10%+
"volup") # Increase audio sink volume by 5%
wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+
;;
"voldown") # Decrease audio sink volume by 10%
wpctl set-volume @DEFAULT_AUDIO_SINK@ 10%-
"voldown") # Decrease audio sink volume by 5%
wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-
;;
"toggle") # Toggle audio sink mute
wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
@ -98,11 +99,11 @@ case "$type" in
;;
"source") # Actions for audio source
case "$action" in
"volup") # Increase audio source volume by 10%
wpctl set-volume @DEFAULT_AUDIO_SOURCE@ 10%+
"volup") # Increase audio source volume by 5%
wpctl set-volume @DEFAULT_AUDIO_SOURCE@ 5%+
;;
"voldown") # Decrease audio source volume by 10%
wpctl set-volume @DEFAULT_AUDIO_SOURCE@ 10%-
"voldown") # Decrease audio source volume by 5%
wpctl set-volume @DEFAULT_AUDIO_SOURCE@ 5%-
;;
"toggle") # Toggle audio source mute
wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle

52
src/battery Executable file
View file

@ -0,0 +1,52 @@
#!/bin/sh
# Define icon theme and path
icon_theme="Tela-circle-black-dark"
icon_path="/usr/share/icons/${icon_theme}/24/panel"
# Define icon files for different discharging battery states
discharging_empty="${icon_path}/battery-000.svg"
discharging_low="${icon_path}/battery-020.svg"
discharging_medium="${icon_path}/battery-050.svg"
discharging_good="${icon_path}/battery-080.svg"
discharging_full="${icon_path}/battery-100.svg"
# Define icon files for different charging battery states
charging_empty="${icon_path}/battery-020"
charging_low="${icon_path}/battery-020-charging.svg"
charging_medium="${icon_path}/battery-050-charging.svg"
charging_good="${icon_path}/battery-080-charging.svg"
charging_full="${icon_path}/battery-100-charged.svg"
# Get the capacity and charging state of the battery
capacity="$(cat "/sys/class/power_supply/BAT0/capacity")"
charging="$(cat "/sys/class/power_supply/AC/online")"
# Send a different notification based on the charging state
if [ $charging -eq 0 ]; then
# send a different notification based on the capacity
if [ $capacity -gt 90 ]; then
notify-send "Capacity: ${capacity}%" -h int:value:$capacity -h string:synchronous: -i $discharging_full -t 4000
elif [ $capacity -gt 70 ]; then
notify-send "Capacity: ${capacity}%" -h int:value:$capacity -h string:synchronous: -i $discharging_good -t 4000
elif [ $capacity -gt 40 ]; then
notify-send "Capacity: ${capacity}%" -h int:value:$capacity -h string:synchronous: -i $discharging_medium -t 4000
elif [ $capacity -gt 10 ]; then
notify-send "Capacity: ${capacity}%" -h int:value:$capacity -h string:synchronous: -i $discharging_low -t 4000
else
notify-send "Capacity: ${capacity}%" -h int:value:$capacity -h string:synchronous: -i $discharging_empty -t 4000
fi
else
# Send a different notification based on the capacity
if [ $capacity -gt 90 ]; then
notify-send "Capacity: ${capacity}%" -h int:value:$capacity -h string:synchronous: -i $charging_full -t 4000
elif [ $capacity -gt 70 ]; then
notify-send "Capacity: ${capacity}%" -h int:value:$capacity -h string:synchronous: -i $charging_good -t 4000
elif [ $capacity -gt 40 ]; then
notify-send "Capacity: ${capacity}%" -h int:value:$capacity -h string:synchronous: -i $charging_medium -t 4000
elif [ $capacity -gt 10 ]; then
notify-send "Capacity: ${capacity}%" -h int:value:$capacity -h string:synchronous: -i $charging_low -t 4000
else
notify-send "Capacity: ${capacity}%" -h int:value:$capacity -h string:synchronous: -i $charging_empty -t 4000
fi
fi

26
src/brightness Executable file
View file

@ -0,0 +1,26 @@
#!/bin/sh
# Define icon theme and path
icon_theme="Tela-circle-black-dark"
icon_path="/usr/share/icons/${icon_theme}/24/panel"
# Define icon file
brightness_lcd="${icon_path}/gpm-brightness-lcd.svg"
# Loop through each backlight
for backlight_path in /sys/class/backlight/*; do
# Extract backlight from path
backlight="${backlight_path##*/}"
# Read the last brightness notification ID from state, or set default if it does not exist.
last_notify_id="$(cat "$HOME/.local/state/brightness/$backlight" || echo "1024")"
# Get the brightness percentage of the backlight
brightness="$(( 100 * $(cat "$backlight_path/brightness") / $(cat "$backlight_path/max_brightness") ))"
# Send the brightness notification
last_notify_id="$(notify-send "Brightness ${brightness}%" -h int:value:$brightness -h string:synchronous: -i $brightness_lcd -t 2000 -r $last_notify_id -p)"
# Write the last brightness notification ID to state
echo "$last_notify_id" > "$HOME/.local/state/brightness/$backlight"
done