You are not logged in.
Pages: 1
I wrote bash script for battery notifications
/home/iskander/.local/bin/battery-notification.sh
#!/bin/bash
# Battery thresholds for notifications (change as needed)
LOW_THRESHOLD=15
FULL_THRESHOLD=100
# Get current battery percentage using /sys/class/power_supply
BATTERY_STATUS=$(cat /sys/class/power_supply/BAT1/status)
BATTERY_CAPACITY=$(cat /sys/class/power_supply/BAT1/capacity)
# Check if battery is fully charged
if [ "$BATTERY_STATUS" == "Full" ] || [ "$BATTERY_CAPACITY" -eq 100 ]; then
# Display a notification for full battery
notify-send "Battery Full" -u critical -i "battery-full"
fi
# Check if battery percentage is below the low threshold
if [ "$BATTERY_CAPACITY" -le "$LOW_THRESHOLD" ]; then
# Display a low battery notification
notify-send "Battery low" "Battery is at ${BATTERY_CAPACITY}%" -u critical -i "battery-caution"
fiand created systemd timer and service:
/etc/systemd/system/battery-notification.service
[Unit]
Description=Battery Notification Service
[Service]
ExecStart=/home/iskander/.local/bin/battery-notification.sh
[Install]
WantedBy=battery-notification.timer[Unit]
Description=Battery Notification Timer
[Timer]
OnActiveSec=2min
OnUnitActiveSec=2min
[Install]
WantedBy=timers.targetBut after reloading daemon and starting timer notification doesn't appear
Last edited by iskander9908 (2024-02-14 06:46:52)
Offline
Your systemd system service does not have access to the user bus that your notification daemon is running on.
Since this is user specific and doesn't require root rights, setup a proper user service instead. https://wiki.archlinux.org/title/Systemd/User https://wiki.archlinux.org/title/System … user_units
Last edited by V1del (2024-02-07 09:45:45)
Offline
You saved me, thanks
Last edited by iskander9908 (2024-02-14 06:46:23)
Offline
Pages: 1