You are not logged in.

#1 2023-08-19 07:20:04

iskander9908
Member
Registered: 2022-10-30
Posts: 31

Battery notification

Hi

I wrote a script for battery notification, but don't know what is better to execute. Systemd or cron?
Here is the script:

#!/bin/sh

# Battery status check
BATTERY_STATUS=$(cat /sys/class/power_supply/BAT1/status)

# Battery capacity check
BATTETY_LEVEL=$(cat /sys/class/power_supply/BAT1/capacity)

# Show notifications
if [$BATTERY_STATUS -eq 'Discharging' && $BATTERY_LEVEL -le 15]; then
    notify-send -u critical "Battery critical!" "${BATTERY_LEVEL}%"
    paplay /usr/share/sounds/freedesktop/stereo/dialog-warning.oga
elif [$BATTERY_STATUS -eq 'Charging' && $BATTERY_LEVEL -eq 100]; then
    notify-send -u critical "Battery full!" "${BATTERY_LEVEL}%"
    paplay /usr/share/sounds/freedesktop/stereo/dialog-warning.oga
fi

Last edited by iskander9908 (2023-08-19 07:23:12)

Offline

#2 2023-08-19 09:44:30

jonno2002
Member
Registered: 2016-11-21
Posts: 868

Re: Battery notification

use whatever works best for you.

arch wiki wrote:

There are many cron implementations, but none of them are installed by default as the base system uses systemd/Timers instead.

i personally just use systemd timers for that exact reason.

Offline

Board footer

Powered by FluxBB