diff --git a/auto/restartservices.sh b/auto/restartservices.sh index 12b0865..0998a7d 100644 --- a/auto/restartservices.sh +++ b/auto/restartservices.sh @@ -1,4 +1,3 @@ chmod +x $PWD/run.sh sudo systemctl daemon-reload sudo systemctl restart shownotif.service - diff --git a/auto/run.sh b/auto/run.sh index 094bd1c..6084739 100755 --- a/auto/run.sh +++ b/auto/run.sh @@ -1,6 +1,7 @@ #!/bin/bash PER=$(( $(cat /sys/class/power_supply/BAT1/charge_now) * 100 / $(cat /sys/class/power_supply/BAT1/charge_full) )) +SCRIPT_DIR=$(dirname -- "$( readlink -f -- "$0"; )") # Check if the PC is charging @@ -11,7 +12,7 @@ declare -A props # Load properties from file load_props() { - local file="$PWD/props.txt" + local file="$SCRIPT_DIR/props.txt" if [[ -f "$file" ]]; then while IFS='=' read -r key value; do props["$key"]="$value" @@ -26,7 +27,7 @@ load_props() { # Save properties to file save_props() { - local file="$PWD/props.txt" + local file="$SCRIPT_DIR/props.txt" > "$file" for key in "${!props[@]}"; do echo "$key=${props[$key]}" >> "$file" @@ -39,31 +40,31 @@ load_props # Battery percentage-based logic if [[ "$PER" -le 10 ]]; then # Always show notification if battery is 10% or less - bash $PWD/shownotif.sh lowbat + bash $SCRIPT_DIR/shownotif.sh lowbat elif [[ "$PER" -le 20 && "${props["lowchargenotifsent"]}" == "false" ]]; then # Show notification if battery is 20% or less, but only if it hasn't been sent already - bash $PWD/shownotif.sh lowbat + bash $SCRIPT_DIR/shownotif.sh lowbat props["lowchargenotifsent"]=true fi # Check if props["ischarge"] does not match IS_CHARGING and update accordingly if [[ "${props["ischarge"]}" != "$IS_CHARGING" ]]; then if [[ "$IS_CHARGING" == true ]]; then - bash $PWD/shownotif.sh charging-status-mismatch "Now Charging" + bash $SCRIPT_DIR/shownotif.sh charging-status-mismatch "Now Charging" else - bash $PWD/shownotif.sh charging-status-mismatch "Now Unplugged" + bash $SCRIPT_DIR/shownotif.sh charging-status-mismatch "Now Unplugged" fi props["ischarge"]=$IS_CHARGING fi # Check if the PC is charging and show a notification if needed if [[ "$IS_CHARGING" == true && "${props["ischargingnotifshown"]}" == "false" ]]; then - bash $PWD/shownotif.sh charging + bash $SCRIPT_DIR/shownotif.sh charging props["ischargingnotifshown"]=true props["isunpluggednotifshown"]=false # Reset unplugged notification flag when charging elif [[ "$IS_CHARGING" == false && "${props["isunpluggednotifshown"]}" == "false" ]]; then # Show unplugged notification when the PC is no longer charging - bash $PWD/shownotif.sh unplugged + bash $SCRIPT_DIR/shownotif.sh unplugged props["isunpluggednotifshown"]=true props["ischargingnotifshown"]=false # Reset charging notification flag when unplugged fi @@ -78,6 +79,6 @@ TEMP=$(sensors | grep -i 'temp1' | head -n 1 | awk '{print $2}' | sed 's/+//g;s/ # force to int TEMP=${TEMP%.*} -if [ "$TEMP" -gt 20 ]; then - bash $PWD/shownotif.sh temperature +if [ "$TEMP" -gt 75 ]; then + bash $SCRIPT_DIR/shownotif.sh temperature fi